I try to get list of all users with post and link them to different page where all their posts is listed.
Obviously I must make my list page first then my users detail page, but some how I ended up with detail page and no list page :)))
Anyway: this is what I have so far:
Controller
public function chef() {
//
return view('front.chef');
}
public function chefdetail() {
$user = User::find(1);
$user->food()->where('status', 1)->get();
return view('front.chef-detail', compact('user'));
}
My routes:
Route::get('/chef/{username}', 'FrontendController@chefdetail')->name('chefdetail');
Route::get('/chefs', 'FrontendController@chef')->name('chefs');
Questions (Problems) :
- How do I get list of users with posts in my
chef
function? - How do I add
username
to my chefs detail page URL
Is it correct that I used
$user = User::find(1);
to getting users list? because I couldn't get users by id it returns error.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire