Laravel Tip: Saving/Updating Eloquent model with associated entities with single line of code
Imagine you have two entities Employees and Department.
Usually if you want to update something in department and its associated employee you will do something like this:
However you save all associated relationships in a single line with just:
$department->push();
Source: https://laravel.com/docs/8.x/eloquent-relationships#the-push-method
Comments
Post a Comment