lundi 24 octobre 2016

How to pass parameter to implicit controller in Laravel 5?

In both laravel 4.2 and laravel 5.3, there is an option in route to use implicit controller. The syntax are the same for both version.

Route::controller('myroute', 'myDearController');

So the URL will be:

http://ift.tt/2faTuGD

In laravel 4, the controller will look like:

//..... Some other controller related syntax ......
public function getFunctionName($parameter1, $parameter2) {
    $inputs = Input::all();
    dd($inputs);
}
//..... Some other controller related syntax ......

However, in laravel 5, to get the GET input, it takes up a parameter place, so I tried to make something like this:

//..... Some other controller related syntax ......
public function getFunctionName(Request $request, $parameter1, $parameter2) {
    $inputs = $request->all();
    dd($inputs);
}
//..... Some other controller related syntax ......

However, the URL returns The site can't be reached. I tried switching the position,

//..... Some other controller related syntax ......
public function getFunctionName( $parameter1, $parameter2, Request $request) {
    $inputs = $request->all();
    dd($inputs);
}
//..... Some other controller related syntax ......

It does not work. I know I can add the line Route::get('myroute/function-name/{$parameter1}/{$parameter2}', 'myDearController@getFunctionName') to the route file, but besides explicitly specify in the route file, is there a default way to do so?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire