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
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);
 }
Example #2
0
 public function newPivot(Model $parent, array $attributes, $table, $exists)
 {
     if ($parent instanceof Shift) {
         return new EmployeeShiftPivot($parent, $attributes, $table, $exists);
     }
     return parent::newPivot($parent, $attributes, $table, $exists);
 }
Example #3
0
 public function newPivot(Model $parent, array $attributes, $table, $exists)
 {
     if ($parent instanceof Member) {
         return new MembersEvents($parent, $attributes, $table, $exists);
     }
     return parent::newPivot($parent, $attributes, $table, $exists);
 }
Example #4
0
 public function newPivot(Model $parent, array $attributes, $table, $exists)
 {
     if ($parent instanceof Student) {
         return new StudentSubjectPivot($parent, $attributes, $table, $exists);
     }
     return parent::newPivot($parent, $attributes, $table, $exists);
 }
 public function newPivot(Model $parent, array $attributes, $table, $exists)
 {
     if ($parent instanceof Endpoint) {
         return new FieldEndpoint($parent, $attributes, $table, $exists);
     }
     return parent::newPivot($parent, $attributes, $table, $exists);
 }
Example #6
0
 public function newPivot(Model $parent, array $attributes, $table, $exists)
 {
     if ($parent instanceof \App\Project) {
         return new \App\ProjectServerPivot($parent, $attributes, $table, $exists);
     }
     return parent::newPivot($this->parent, $attributes, $this->table, $exists);
 }
Example #7
0
 /**
  * Overrides default newPivot method to provide extra logic....
  * REVIEW???
  * @param Model $parent Parent object of pivot table
  * @param array $attributes Custom defined columns for pivot table
  * @param string $table Table name to give to the pivot
  * @param boolean $exists
  */
 public function newPivot(Model $parent, array $attributes, $table, $exists)
 {
     if ($parent instanceof Department) {
         return new DepartmentUser($parent, $attributes, $table, $exists);
     }
     return parent::newPivot($parent, $attributes, $table, $exists);
 }
Example #8
0
 /**
  * Create a new pivot model instance.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $parent
  * @param  array  $attributes
  * @param  string  $table
  * @param  bool  $exists
  * @return \Illuminate\Database\Eloquent\Relations\Pivot
  */
 public function newPivot(EloquentModel $parent, array $attributes, $table, $exists)
 {
     $modelClass = get_class($parent);
     if (isset($this->pivots[$modelClass])) {
         $pivotClass = $this->pivots[$modelClass];
         return new $pivotClass($parent, $attributes, $table, $exists);
     }
     return parent::newPivot($parent, $attributes, $table, $exists);
 }
Example #9
0
 public function newPivot(Model $parent, array $attributes, $table, $exists)
 {
     if ($this instanceof Transaction && $parent instanceof Account) {
         return new SplitPivot($parent, $attributes, $table, $exists);
     }
     if ($this instanceof Account && $parent instanceof Transaction) {
         return new SplitPivot($parent, $attributes, $table, $exists);
     }
     return parent::newPivot($parent, $attributes, $table, $exists);
 }
Example #10
0
 /**
  * @param Model  $parent
  * @param array  $attributes
  * @param string $table
  * @param bool   $exists
  *
  * @return PermissionUserPivot|\Illuminate\Database\Eloquent\Relations\Pivot
  */
 public function newPivot(Model $parent, array $attributes, $table, $exists)
 {
     $userModel = app()['config']->get('auth.model');
     $roleModel = app()['config']->get('defender.role_model');
     if ($parent instanceof $userModel) {
         return new PermissionUserPivot($parent, $attributes, $table, $exists);
     }
     if ($parent instanceof $roleModel) {
         return new PermissionRolePivot($parent, $attributes, $table, $exists);
     }
     return parent::newPivot($parent, $attributes, $table, $exists);
 }