
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.phppublic function projects(){ return $this->belongsToMany('App\Models\Project') ->withPivot('is_manager', 'order_by') ->withTimestamps(); }
0
Random Code Snippet Queries: Laravel
- Target class [App\Http\Controllers\Auth\Request] does not exist.
- Use withCount() to Calculate Child Relationship Records
- Order by multiple columns in Laravel
- How to create static page in Laravel
- Eager loading dynamically in laravel
- First and last item of the array using foreach iteration in laravel blade
- How to display order by null last in laravel
- How to check records exist in loaded relationship in Laravel blade view
- How to get last year records count with month wise in Laravel
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- Attempt to read property "avatar" on null in Laravel
- How to get list of all views file in laravel
- Seed database using SQL file in Laravel
- Laravel append URI in route
- Pagination in laravel
- Get the post details if it has at least one comment in comments table
- Ajax GET request in laravel
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- Generate unique username in Laravel
- Retrieve count of nested relationship data in Laravel
- How to get all posts which contains comments in laravel
- Declaration of App\Models\Post::sluggable() must be compatible with Cviebrock\EloquentSluggable\Sluggable
- Laravel hasmany select not working
- Permission denied error while creating storage link in Laravel
- Shorter syntax for whereHas with call back function in laravel