Illuminate\Database\Eloquent\Model::newPivot PHP Method

newPivot() public method

Create a new pivot model instance.
public newPivot ( Model $parent, array $attributes, string $table, boolean $exists, string | null $using = null ) : Illuminate\Database\Eloquent\Relations\Pivot
$parent Model
$attributes array
$table string
$exists boolean
$using string | null
return Illuminate\Database\Eloquent\Relations\Pivot
    public function newPivot(Model $parent, array $attributes, $table, $exists, $using = null)
    {
        if ($using) {
            return new $using($parent, $attributes, $table, $exists);
        }
        return new Pivot($parent, $attributes, $table, $exists);
    }

Usage Example

Example #1
3
 public function newPivot(Model $parent, array $attributes, $table, $exists)
 {
     if ($parent instanceof Order) {
         return new ProductPrice($parent, $attributes, $table, $exists);
     }
     return parent::newPivot($parent, $attributes, $table, $exists);
 }
All Usage Examples Of Illuminate\Database\Eloquent\Model::newPivot
Model