Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cedricmatalog's avatar

Refactoring

https://laracasts.com/series/laravel-from-scratch-2018/episodes/27

is there a cleaner way to do this?

Route::resource('projects', 'ProjectsController')->except(['show', 'create', 'index'])->middleware('can:update,project');
Route::resource('projects', 'ProjectsController')->only(['show', 'create', 'index']);
0 likes
4 replies
Mithrandir's avatar
Level 50

Depends on the definition of "clean".

I wouldn't get the vacuum out for those two lines as they seem pretty clean.

1 like
knubbe82's avatar

Looks clean. Maybe creating a polices would be cleaner for you

1 like
vajid's avatar

you can use do this in controller

//in ProjectsController

public function _construct()
{
    $this->middleware('can:update,project', 'except'=>['show', 'create', 'index']);
}

//cleaning web.php
Route::resource('projects', 'ProjectsController');

not sure about resource controller routes

Route::resource('projects', 'ProjectsController')->only(['show', 'create', 'index']);

Please or to participate in this conversation.