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
}
There are many methods to do this.
Method 1
If you make the url like below:
<a href="http://localhost/travel/tr/approveRequest/<?=$Encoded_travelRq_id?>/<?=$Encoded_emp_gslab_id?>/<?=$Encoded_iv?>">Approve</a>;
You can make route with parameters as like below.
Route::get('approveRequest/{par1}/{par2}/{par3}', 'ApproveController@approve');
And in your function get the respective parameter as following:
public function approve($par1,$par2,$par3,)
{
$id = $par1;
$gsID = $par2;
.... and so on for all your variables.
}
Method 2 use request method:
If your url is like:
<a href="http://localhost/travel/tr/approveRequest?id=<?=$Encoded_travelRq_id?>&gsID<?=$Encoded_emp_gslab_id?>&decrypt<?=$Encoded_iv?>/">Approve</a>;
Then define Route Like:
Route::post('approveRequest', 'ApproveController@approve');
Then in your controller function you get parameters as below:
Use Request after the namespace in youe controller class
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class SomeClassController extends Controller {
public function approve(Request $request)
{
$id = $request->id;
$gsID = $request->get('gsID');
.... and so on for all your variables.
}
}
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.