What is Route Parameters ?

Answer Posted / rachana devi

Sometimes in the web application, you may need to capture the parameters passed with the URL.
For this, you should modify the code in routes.php file.

You can capture the parameters in routes.php file in two ways as discussed here -

1. Required Parameters : These parameters are those which should be mandatorily captured for routing the web application.

Example : Route::get('ID/{id}',function($id)
{
echo 'ID: '.$id;
}
);

2. Optional Parameters : Sometimes developers can produce parameters as optional and it is possible with the inclusion of ? after the parameter name in URL.
It is important to keep the default value mentioned as a parameter name.

Example : Route::get('user/{name?}', function ($name = 'Manager') { return $name;});

The example above checks if the value matches to 'Manger' and accordingly routes to the defined URL.


3. Named Routes : Named routes allow a convenient way of creating routes.
The chaining of routes can be specified using name method onto the route definition.

Example : Route::get('user/profile', 'UserController@showProfile')->name('profile');

The user controller will call for the function showProfile with parameter as profile. The parameters use name method onto the route definition.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain short brief on Facades in Laravel ?

754


How to return a view from route in laravel?

418


What are middleware groups?

425


What are the steps to configure homestead?

454


What is Decryption Process ?

872






Explain the difference between laravel and codeigniter?

417


Is any server permissions required for laravel?

452


What are common http error codes?

439


How to use laravel framework in php?

398


How can someone turn off csrf protection for a specific route?

407


Is laravel a cms?

410


What is meant by Retrieving Input ?

867


Explain how can you write your own service provider in laravel?

423


Tell us how long have you been using laravel?

421


What is escape string?

414