Skip to content

Latest commit

 

History

History
16 lines (15 loc) · 404 Bytes

save_model_and_its_relationships_in_one_go.md

File metadata and controls

16 lines (15 loc) · 404 Bytes

Save model and its relationships in one go

You can save a model and its corresponding relationships using the push() method.

class User extends Model
{
    public function phone()
    {
        return $this->hasOne('App\Phone');
    }
}
$user = User::first();
$user->name = "Peter";
$user->phone->number = '1234567890';
$user->push(); // This will update both user and phone record in DB