laravel many to many relation name code example
Example 1: many to many relationship laravel
use App\Models\User;
$user = User::find(1);
$user->roles()->attach($roleId);
Example 2: laravel relation has many
// Post model
public function comments()
{
return $this->hasMany(Comment::class);
}
// Post controller
$comments = Post::find(1)->comments;