Eloquent provides methods that are convenient incorporating brand new models to relationships. As an example, perchance you have to include a new comment to a post.

Eloquent provides methods that are convenient incorporating brand new models to relationships. As an example, perchance you have to include a new comment to a post.

in the place of manually establishing the post_id characteristic on the Comment model you may possibly place the remark utilizing the relationship’s conserve technique:

Keep in mind that we did not access the reviews relationship as a property that is dynamic. Rather, we called the remarks solution to get an example of this relationship. The salvage method will immediately add the correct post_id value to this new Comment model.

You may use the saveMany method if you need to save multiple related models:

Continue reading