Reputation: 59
Good night, I'm working on a Laravel project. I did a "Your Profile" button that redirects you to your profile, but i have an InvalidArgumentException: View [.profilePage.{user}] not found.
my UserPolicy.php function:
public function Owner(User $user,User $destinationUser){
return $user->id == $destinationUser->id;
}
my UserController.php
public function profile(User $user)
{
$this->authorize('Owner', $user);
return view('/profilePage/{user}', compact('user',$user));
}
my web.php
Route::get('/profilePage/{user}', 'UserController@profile');
my navbar.blade.php layout:
<a class="dropdown-item" href="{{url('/profilePage/'.Auth::user()->id)}}">Your profile</a>
I don't know where is the error and I'm needing help.
Upvotes: 0
Views: 1847
Reputation: 50481
To resolve your view not found issue you need to pass the actual view name you want to be returned, without the extension:
return view('ProfilePage', compact('user'));
Your link is correct in the view though:
url('profilePage/'. Auth::user()->id)
will generate a URL like: http://yoursite.test/profilePage/1
Laravel 6.x Docs - Views - Creating Views view
Laravel 6.x Docs - URLs - Generating Basic URLs url
PHP Manual - Array Functions compact
Upvotes: 1
Reputation: 2110
The line return view('/profilePage/{user}', compact('user',$user));
is incorrect.
view() accepts a path/file in dot notation format.
What you are looking for is something like this:
public function profile(User $user)
{
$this->authorize('Owner', $user);
return view('profile.show', compact('user'));
}
The above code would return the view in resources\views\profile\show.blade.php
The route entry itself Route::get('/profilePage/{user}', 'UserController@profile');
will create the actual endpoint /profilePage/1
, not the view returned in the controller.
Upvotes: 0