$profile = User::findOrFail($id)->all();
This is returning every user in your database. Drop the all()
$profile = User::findOrFail($id);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
So i have created a users online page and each username is a link to their profiles however,
I cannot quite figure out how to do this..
Here is my Controller:
public function user(User $id)
{
$profile = User::findOrFail($id)->all();
return view('profile.profile', compact('profile'));
}
Here is my route:
Route::get('/profile/{id}', [
'as' => 'id',
'uses' => 'ProfileController@user'
]);
For some reason I can't echo out the users information yet, when I var_dump it, it shows everything I am trying to get..
I assume this is the correct url..
1 is the user id of the user..
Here is the clean way to do it..
web.php
Route::get('/profile/{user}','ProfileController@user');
ProfileController.php
public function user(User $user)
{
return view('profile.profile', compact('user'));
}
This is called Implicit Route Model Binding
Please or to participate in this conversation.