Answers for "detach many to many laravel"

PHP
1

laravel has many

public function comments()
 {
   return $this->hasMany(Comment::class);
 }
Posted by: Guest on June-03-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 "detach many to many laravel"

Browse Popular Code Answers by Language