gsk
gsk

Reputation: 2379

Pass parameter from route to controller in laravel?

I want to pass current agency id from route to controller in laravel 5.2.

ex:- I have one resource controller is AgencyController.

Route::resource('agencies', 'Admin\AgencyController');

I want to add one more route, such as,

Route::get('agencies/me', 'Admin\AgencyController@show', ['middleware' => ['web', 'agency']]);

Here I want to pass agency id from session as default parameter to agencyController@show function.

ex:- Auth::guard('agency')->user()->agencies_id

Is it possible in laravel?

Upvotes: 0

Views: 2032

Answers (1)

Norgul
Norgul

Reputation: 4783

Laravel routes function that if you configure your route like:

Route::get('user/{user}', 'UserController@someMethod');

you can pick up whatever you send after the slash in the controller. So if you call:

www.example.com/user/3

and your controller is like public function someMethod($id) the 3 will be forwarded to $id variable

Upvotes: 1

Related Questions