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

push() public method

Save the model and all of its relationships.
public push ( ) : boolean
return boolean
    public function push()
    {
        if (!$this->save()) {
            return false;
        }
        // To sync all of the relationships to the database, we will simply spin through
        // the relationships and save each model via this "push" method, which allows
        // us to recurse into all of these nested relations for the model instance.
        foreach ($this->relations as $models) {
            $models = $models instanceof Collection ? $models->all() : [$models];
            foreach (array_filter($models) as $model) {
                if (!$model->push()) {
                    return false;
                }
            }
        }
        return true;
    }

Usage Example

Example #1
0
 /**
  * Append one or more values to an array.
  *
  * @return mixed
  */
 public function push()
 {
     if ($parameters = func_get_args()) {
         $unique = false;
         if (count($parameters) == 3) {
             list($column, $values, $unique) = $parameters;
         } else {
             list($column, $values) = $parameters;
         }
         // Do batch push by default.
         if (!is_array($values)) {
             $values = [$values];
         }
         $query = $this->setKeysForSaveQuery($this->newQuery());
         $this->pushAttributeValues($column, $values, $unique);
         return $query->push($column, $values, $unique);
     }
     return parent::push();
 }
All Usage Examples Of Illuminate\Database\Eloquent\Model::push
Model