so I have a many-to-many pivot table (project_user)
I'm successful in getting all the projects of the authenticated user
WriterController.php
public function writerProjects()
{
//
$projects = auth()->user()->projects;
dd($projects);
return view('writers.projects', compact('projects'));
}
web.php
Route::get('users/{user}/projects', [
'as' => 'showProjects', 'uses' => 'WriterController@writerProjects']);
My question is how can I get the specific project's details?
My approach so far (it doesn't work though).
public function showWriterProjects($id)
{
//todo
$projects = auth()->user()->projects;
foreach($projects as $p)
{
dd($p->name);
}
return view('writers.projects.show', compact('projects'));
}
web.php for that
Route::get('users/{user}/projects/{project}', [
'as' => 'showSingleProject', 'uses' =>
'WriterController@showWriterProjects']);
What am I doing wrong?
Many-to-Many relations have been defined in User.php and Project.php, they seemed pretty obvious to post.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire