How to create projects method with belongstomany relationship in user model

You can create the projects method with belongstomany relationship in user model. You have to also create a project_user pivot table to get the data from the pivot table.

Answers 1
  • Create belongs to many relationship with projects method in user model

    --PATH App\Models\User.php
    public function projects(){
            return $this->belongsToMany('App\Models\Project')
                        ->withPivot('is_manager', 'order_by')
                        ->withTimestamps();
        }
    
    0
  • Back to code snippet queries related laravel