Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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);
Source by riptutorial.com #
 
PREVIOUS NEXT
Tagged: #laravel
ADD COMMENT
Topic
Name
2+2 =