0

Team,

I am using Laravel 5.1, In which I have to use URI segment feature same as Codeigniter

Like eg. URL - www.example.com/user_id/user_type/user_role/....

Want to access those parameters user_id, user_type, user_role in controller and also want to manage the Route file.

Can anyone guide me how to do this in LARAVEL?

Thanks in Advance

Manos Nikolaidis
  • 21,608
  • 12
  • 74
  • 82
Sanjay M
  • 1
  • 4

2 Answers2

0

In your routes.php file:

Route::get('user/{user_id}/{user_type}/{user_role}', ['uses' => 'UserController@index', 'as' => 'user.index']);

In your UserController.php file:

public function index($user_id, $user_type, $user_role) {
  dd($user_id, $user_type, $user_role);
}
  • Thank you for your reply, But I need the dynamic solution, Where we can send as many variable in link irrespective of route change. – Sanjay M Jan 29 '16 at 13:38
0

In your route.php file write this - If you have any optional parameter then put a Question mark(?) after that, I assumed that the parameter user_role is optional.

 Route::get('user/{user_id}/{user_type}/{user_role?}', [
    'uses' => 'UserController@getIndex',
    'as' => 'user.get.index' // You can write any unique name you want, This will be your route name.
 ]);

In your Controller, You can access these parameters like this -

 public function getIndex($user_id, $user_type, $user_role) {
    // Here your parameters will be available to use.
   //  Write your logic
 }
Keshari Nandan
  • 1,040
  • 9
  • 22