Answers for "laravel one to many realtionship"

PHP
0

one to many laravel

Suppose you have a Post model with a hasMany relationship with Comment. You may insert a Comment object related to a post by doing the following:

$post = Post::find(1);
$commentToAdd = new Comment(['message' => 'This is a comment.']);
$post->comments()->save($commentToAdd);
Posted by: Guest on July-14-2021

Code answers related to "laravel one to many realtionship"

Browse Popular Code Answers by Language