Support the ongoing development of Laravel.io →
posted 7 years ago

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

Last updated 3 years ago.
0

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.

0

@Juha: That's indeed the road i took. Thanks for replying!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.