I'm learning Laravel and I wanna group some routes using prefix and naming each route so I got something like this
Route::prefix('customers')->group(
function(){
Route::get('/', 'CustomerController@index')->name('customers.index');
Route::get('/create', 'CustomerController@create')->name('customers.create');
Route::post('/', 'CustomerController@store')->name('customers.store');
});
I want to avoid writing 'customers.' in every route name.
I have tried with group and name but it doesn't recognize the route name prefix 'customers.'
Route::group(['prefix' => 'customers', 'name' => 'customers.'],
function(){
Route::get('/', 'CustomerController@index')->name('index');
Route::get('/create', 'CustomerController@create')->name('create');
Route::post('/', 'CustomerController@store')->name('store');
});
The other way I found was with as and use but it seems to much code, and doesn't look kind of clean, actually the first one looks like a cleaner way.
Route::group([
'prefix' => 'customers',
'as' => 'customers.'
],
function(){
Route::get('/', ['as'=>'index', 'uses' => 'CustomerController@index']);
Route::get('/create', ['as'=>'create', 'uses' => 'CustomerController@create']);
Route::post('/', ['as'=>'store', 'uses' => 'CustomerController@store']);
});
Is there a better way to do it?