Ответ 1
Ей магия за кулисами...
/**
* Save the model and all of its relationships.
*
* @return bool
*/
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)
{
foreach (Collection::make($models) as $model)
{
if ( ! $model->push()) return false;
}
}
return true;
}
Это просто показывает, что push()
обновит все модели, относящиеся к рассматриваемой модели, поэтому, если вы измените какие-либо отношения, вызовите push()
Он обновит эту модель и все ее отношения
Так вот...
$user = User::find(32);
$user->name = "TestUser";
$user->state = "Texas";
$user->location->address = "123 test address"; //This line is a pre-defined relationship
Если вы просто...
$user->save();
Тогда адрес не будет сохранен в адресной модели.... Но если вы..
$user->push();
Затем он сохранит все данные и сохранит адрес в адресе table/model
, потому что вы определили это отношение в User model
.
push()
также обновит все обновленные метки времени всех связанных моделей любого пользователя/модели, которые вы push()
Надеюсь, это очистит вещи....