Laravel Get Url Parameters
Laravel Get Url Parameters : If you are working with laravel, generally you need to access url parameter and their respective values. Laravel provides few simple methods to access url parameters and their values. We will explain the methods available in laravel which are useful in manipulating the url parameters. We will cover how to validate the url parameter whether it consists data or it is null.
Laravel Get Url Parameters Syntax
Here are examples and syntax to get Url parameters. Let us go step by step to learn the things easily –
Get Url Parameters
You can retreive url parameters as below –
Retrieve Url Parameter
$parameter_name = Input::get('parameter_name'); |
Where parameter_name is name of parameter you want to retrieve from url.
More About Url Parameters
Let’s have look over more example about url parameters here.
Set A default value and Retrieve It
It the value in url parameter is null you can set a default value for that parameter which will return defualt value in case the parameter retrieves null value.
Retrieve Url Parameter
$parameter_name = Input::get('parameter_name','default'); |
Will return default if the url parameter is null ie. absent.
Check if value isset/exists –
Set Default Input Parameter
$parameter_name = Input::get('parameter_name'); // returns true if value exists if($parameter_name){ } |
Get All Request Values –
If want to retrieve all values in request you can use following method as below-
Retrieve All Url Parameter
$all_params = Input::all(); // returns all params array |
it will return all parameters together.
Advertisements