Using the Laravel 5 Injection Method with Other Parameters

So, I am working on an admin interface. I have a route configured like this:

Route::controllers([
    'admin' => 'AdminController',
]);

Then I have a controller with some methods:

public function getEditUser($user_id = null)
{
    // Get user from database and return view
}

public function postEditUser($user_id = 0, EditUserRequest $request)
{
    // Process any changes made
}

As you can see, I am using the injection method to validate user input, so the URL will look like this:

http://example.com/admin/edit-user/8697

The GET request will be passed to the GET method and the POST request to the POST method. The problem is that if I create a new user, the identifier will not be:

http://examplecom/admin/edit-user/

Then I get the error message (rephrased):

Argument 2 passed to the controller must be an instance of EditUserRequest not specified

, 0, , , ? , , ? .

+4
1

, :

public function postEditUser(EditUserRequest $request, $user_id = null)
{

}

Laravel EditUserRequest , user_id, .

+2

All Articles