Ad

How To Optimize The Uses Controller In Laravel Route Group?

Route::group(['as' => 'admin.documents', 'middleware' => 'permissions:volunteer', 'prefix' => 'admin/documents/', 'namespace' => 'Admin/'], function () {
    Route::get('', ['uses' => 'AdminDocumentsContr[email protected]',    'as' => '',         ]);
    Route::get('add', ['uses' => '[email protected]',   'as' => '.create',  ]);
    Route::post('add', ['uses' => '[email protected]',   'as' => '.create' 
});

How can even optimize this code? ALSO find namespace but AdminDocumentsController its not look goods

Ad

Answer

Add namespace to the first route group, then remove the Admin from the uses

Route::group(['namespace' => 'Admin', 'as' => 'admin.documents', 'middleware' => 'permissions:volunteer', 'prefix' => 'admin/documents/'], function () {
    Route::get('', ['uses' => '[email protected]',    'as' => '',         ]);
    Route::get('add', ['uses' => '[email protected]',   'as' => '.create',  ]);
});
Ad
source: stackoverflow.com
Ad