06.10.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Eloquent: Relationships 602<br />

1 $user->roles()->sync([1 => ['expires' => true], 2, 3]);<br />

Touching Parent Timestamps<br />

When a model belongsTo or belongsToMany another model, such as a Comment which belongs to a<br />

Post, it is sometimes helpful to update the parent’s timestamp when the child model is updated. For<br />

example, when a Comment model is updated, you may want to automatically “touch” the updated_at<br />

timestamp of the owning Post. Eloquent makes it easy. Just add a touches property containing the<br />

names of the relationships to the child model:<br />

1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!