basagabi basagabi - 1 year ago 100
PHP Question

Laravel option route parameter not working

I'm using laravel 5.2 and having problems with regards to routing. Supposed I have this route:

Parameter1 should be required while Parameter2 should be optional. When user enter this url:
or this
, they should be able to proceed. By when this is entered,
they will be redirected to the homepage.

Here's my route:

Route::get('out/{param1}/{param2?}', 'MyController@out']);
Route::get('out/', 'MyController@redirect']);

The controller:

public function out($param1, $param2 = '', Request $request) {
// logic here

The error that I'm getting is this:
Argument 3 passed to App\Http\Controllers\MyController::out() must be an instance of Illuminate\Http\Request, none given

I already specify a default value for
on the method.

Answer Source

Request instance must be the first one

public function out(Request $request, $param1, $param2 = '') 
    // logic here

Docs: under Method Injection

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download