Am using Laravel route for approving some form from email. So i have encrypted some variables and created link which is like:
<a href="http://localhost/travel/tr/approveRequest?id=<?=$Encoded_travelRq_id?>&gsID<?=$Encoded_emp_gslab_id?>&decrypt<?=$Encoded_iv?>/">Approve</a>;
Now how route can be written for this on Laravel side in which i can seperate the variables like id, gsID, decrypt from url and can send to controller's function used against that route?
The required parameters are the parameters that we pass in the URL. Sometimes you want to capture some segments of the URI then this can be done by passing the parameters to the URL. For example, you want to capture the user id from the URL. Let's see the example without route parameters.
To retrieve the query parameters on your Laravel backend, you can make use of either the "Request" class or the "request()" helper method. Imagine you want to get the "search" query from the URL, you can do as follows. $searchQuery = $request->query('search');
Routing in Laravel allows you to route all your application requests to its appropriate controller. The main and primary routes in Laravel acknowledge and accept a URI (Uniform Resource Identifier) along with a closure, given that it should have to be a simple and expressive way of routing.
Usually I use two ways:
1º way:
The route:
Route::get('approveRequest', 'ApproveController@approve');
The controller:
public function approve (Request $request) {
$var1 = $request->input('var1');
$var2 = $request->input('var2');
// (...) do something with $var1 and $var2
}
2º way:
The route:
Route::get('approveRequest/{var1}/{var2}', 'ApproveController@approve');
The controller:
public function approve ($var1, $var2) {
// (...) do something with $var1 and $var2: they already have a instance
}
Simply write a GET
route to approveRequest
:
Route::get('approveRequest', 'ApproveController@approve');
Because you are using URL parameters, you can simply get them in the approve()
function like this
public function approve(Request $request)
{
$id = $request->id;
$gsID = $request->get('gsID');
.... and so on for all your variables.
}
With this approach the order of parameters does not matter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With