Recover URL Parameter Laravel

203 Views Asked by At

My front sends parameters in the url and I would like to get them back to my laravel controller.

My route (back)

Route::get('publication/Mls/{status}/{typeTransac}', 'MlsController@getIndicatorMlsList');

The console shows me this on the front side

api/user/publication/Mls?status=Archive&typeTransac=Vente

How do I get this information back?

2

There are 2 best solutions below

1
zahid hasan emon On BEST ANSWER

they are not the same route. you have to change either in front end or back end. the front end url is

api/user/publication/Mls?status=Archive&typeTransac=Vente

in this url api/user/publication/Mls is the base url and ?status=Archive&typeTransac=Vente is request parameter. to get it in the laravel side you need a route like

Route::get('publication/Mls', 'MlsController@getIndicatorMlsList');

assuming you have user prefixed in your route. if not you have to add that too in your route.

now in your controller you can access the request parameter

public function getIndicatorMlsList (Request $request)
{
    $status = $request->status;
    $typeTransac = $request->typeTransac;
}

or you can keep your back end route as same as it is now and change the front end url

api/user/publication/Mls/Archive/Vente

and in the controller

public function getIndicatorMlsList ($status, $typeTransac)
{
    //the function parameters are the values from the url
}
0
A.A Noman On

You have to use like this

public function getIndicatorMlsList($status, $typeTransac){
    // your rest code
}