Answers for "laravel eloquent many to many"

PHP
1

many to many relationship laravel

use AppModelsUser;

$user = User::find(1);

$user->roles()->attach($roleId);
Posted by: Guest on February-13-2021
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 eloquent many to many"

Browse Popular Code Answers by Language