stefan de boer
stefan de boer

Reputation: 405

Passing a user id in a url in laravel

I'm making a Laravel web application, in this application, I have an Account Settings page. On this page, I want to display all the orders the user has made. In order to do this, I have to get the User id from the URL.

I tried passing the User id thru the URL by putting the Auth::user()->id in the route that leads to the page. however, this is giving me a 404 not found error.

This is the link that should pass the ID in the URL.

 <a class="dropdown-item" href="{{ route('account/{{ Auth::user()->id }}') }}">
 {{ __('Account Settings') }}
 </a>

I also tried to change my web.php file but that's also not giving any result.

I really would appreciate some help with my problem since I've been stuck on this all day.

Upvotes: 1

Views: 2812

Answers (1)

MyLibary
MyLibary

Reputation: 1771

You're using Laravel route helper. the route would work only for NAMED ROUTE, for example:

Route::get('account/{userId}', 'AccountController@show')->name('account');

Then, your could should be:

<a class="dropdown-item" href="{{ route('account', ['userId' => Auth::id()]) }}">
 {{ __('Account Settings') }}
</a>

Upvotes: 3

Related Questions