Any easy way to pass only one parameter to controller action?

Posted 1 year ago by itstrueimryan

So my setup is something like this:

Route::group(['prefix' => '{organization_name}', 'middleware' => ['auth', 'administers_organization']], function () {
    /** Users */
    Route::get('/users/{id}/edit', '[email protected]')->middleware('record_exists:App\Models\User');
    Route::resource('users', 'UserController');

But for the edit action in the UserController, I'm getting both the prefix and the id parameters passed. Is there a simple way to not pass the prefix variable to any of the controller actions? The only place I'm checking this variable is in the administers_organization middleware, so I'd rather not have to add an extra unused param in a bunch of actions just to get to the second param, $id.

To clarify, I'm trying to avoid having to do this:

public function edit(Request $request, UserRepository $user, $organizationName, $id)

In favor of:

public function edit(Request $request, UserRepository $user, $id)

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.