Hi,
I have two routes:
Route::get('user/{user}', 'UserController@user')->name('playground.user');
Route::get('customer/{customer}/user/{user}', 'UserController@user')->name('playground.customer.user');
And this is the controller method:
public function user(Request $request, User $user, Customer $customer = null)
{
return view('admin.user', compact('user', 'customer'));
}
The second route fails because the order of the arguments in the controller method is wrong (expecting a User and a Customer given).
I want the routes as they are, so i was wondering if it would be possible in the route, to switch the arguments before being injected in the controller method...
Best,
Richard
Out of the box I don’t think so. Why don’t you just add a new method that wraps your existing controller method? It is a good practice to have your controller method’s arguments stickly defined and validated.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community