0

I'm buiding a user management system. The current routes on web.php are here:

Route::middleware(['admin'])
    ->prefix('users')
    ->name('users.')
    ->group(function() {
        Route::get('management/list', '\App\Http\Controllers\UserController@list');
        Route::resource('management', '\App\Http\Controllers\UserController');
    });

I have two levels of user: Administrator (middleware is admin) and Collaborator (middleware is auth).

My problem is with the route of edit and update from the users resource: users/management/{management}/edit

How can I do something like that to the users from auth middleware, to allow the route just if the parameter be the own user id for the Collaborator users?

Route::middleware(['auth'])
    ->prefix('users')
    ->name('users.')
    ->group(function() {
        Route::get('management/{auth()->id}/edit', '\App\Http\Controllers\UserController@edit');
    });
1

1 Answer 1

0

I'm not sure you can do this however you can just look up the user again in your controller

Route::middleware(['auth'])
    ->prefix('users')
    ->name('users.')
    ->group(function() {
        Route::get('management/currentuser/edit', '\App\Http\Controllers\UserController@edit');
    });

This is also better practice as you are looking up logged in user not any user.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.