#laravel #laravel-5 #laravel-5.3
#ларавель #laravel-5 #laravel-5.3
Вопрос:
У меня есть два одинаковых контроллера в разных каталогах.
И маршрутизация предназначена для обоих:
Route::resource('dashboard/statistic', 'AdminStatisticController');
Route::resource('statistic', 'StatisticController');
When I run php artisan route:list
Я вижу, что эти маршруты имеют то же название маршрута, что и: statistic
:
statistic.index
statistic.destroy
statistic.edit
Как я могу сделать это по-разному?
Комментарии:
1. Все это есть в документации: laravel.com/docs/5.3/routing#named-routes
2. Хорошо, тогда как это сделать для
resource
3. Также в документации: laravel.com/docs/5.3/controllers#restful-naming-resource-routes — i.imgur.com/MZEMKLf.png
Ответ №1:
Вы могли бы создать каждый маршрут явно ( Route::resource creates multiple routes to handle a variety of RESTful actions on the resource
), например
Route::get('dashboard/statistic', ['as' => 'dashboard-statistic.index', 'uses' => 'AdminStatisticController@index']);
Route::delete('dashboard/statistic', ['as' => 'dashboard-statistic.destroy', 'uses' => 'AdminStatisticController@destroy']);
Route::put('dashboard/statistic', ['as' => 'dashboard-statistic.edit', 'uses' => 'AdminStatisticController@edit']);
Ответ №2:
Может быть
Route::resource('dashboard/statistic', 'AdminStatisticController',
['admin' => ['create', 'store', 'update', 'destroy']]);
Route::resource('statistic', 'StatisticController');
Надеюсь, это решит вашу проблему
Ответ №3:
может быть, это может решить проблему
Route::group(['prefix' => 'dashboard', 'as' => 'dashboard.'], function() {
Route::resource('statistic', 'AdminStatisticController');
});
вернет имя, например:
dashboard.statistic.store