I have two tables in relation users and projects. In users table I have addiotional field admin_id
.
Pivot table is project_user
with columns: id, user_id, project_id and additonal field admin_id
When I selecting projects from database I need also to check if admin_id from pivot table
is equal
with admin_id from users table
is it possible???
Here is my User modal:
public function projects(){
return $this ->belongsToMany('App\Project','project_user')->withPivot('admin_id');
}
Here is Controller:
public function project(Project $project){
//TAKING PROJECTS FORM CURRENT ID
$projects = User::findOrFail(Auth::user() -> id) ;
//NOT IMPORTANTE
$users = User::lists('name','id');
return view('projects',array('projects' => $projects,'users' => $users ));
}
Blade:
@foreach($projects -> projects as $project)
<a href="#" class="list-group-item">{{ $project -> name }}</a>
@endforeach