我定义了以下路线:
// Supplier routes
Route::middleware(['web', 'guest'])->namespace('supplier')->name('supplier.')->group(function()
{
Route::get('/', 'AuthController@index')->name('auth.login');
Route::post('/', 'AuthController@handle_login')->name('auth.login.submit');
Route::get('forgotten-password', 'AuthController@forgotten_password')->name('auth.forgotten_password');
Route::post('forgotten-password', 'AuthController@handle_forgotten_password')->name('auth.forgotten_password.submit');
Route::get('forgotten-password/reset/{token}', 'AuthController@reset_password')->name('auth.reset_password');
Route::post('forgotten-password/reset/{token}', 'AuthController@handle_reset_password')->name('auth.reset_password.submit');
});
Route::middleware(['web', 'role:supplier'])->namespace('supplier')->name('supplier.')->group(function()
{
Route::get('logout', 'AuthController@logout')->name('auth.logout');
Route::get('user', 'AuthController@profile')->name('profile');
Route::post('user', 'AuthController@update_profile')->name('profile.submit');
Route::get('dashboard', 'AuthController@dashboard')->name('dashboard');
Route::get('rfqs/datatable', 'RfqController@datatable')->name('rfqs.datatable');
Route::get('rfqs/{id}/delete', 'RfqController@destroy')->name('rfqs');
Route::resource('rfqs', 'RfqController');
});
// Admin routes
Route::middleware(['web', 'guest'])->prefix('admin')->namespace('admin')->name('admin.')->group(function()
{
Route::get('/', 'AuthController@index')->name('auth.login');
Route::post('/', 'AuthController@handle_login')->name('auth.login.submit');
Route::get('forgotten-password', 'AuthController@forgotten_password')->name('auth.forgotten_password');
Route::post('forgotten-password', 'AuthController@handle_forgotten_password')->name('auth.forgotten_password.submit');
Route::get('forgotten-password/reset/{token}', 'AuthController@reset_password')->name('auth.reset_password');
Route::post('forgotten-password/reset/{token}', 'AuthController@handle_reset_password')->name('auth.reset_password.submit');
});
Route::middleware(['web', 'role:admin'])->prefix('admin')->namespace('admin')->name('admin.')->group(function()
{
Route::get('logout', 'AuthController@logout')->name('auth.logout');
Route::get('user', 'AuthController@profile')->name('user.profile');
Route::post('user', 'AuthController@update_profile')->name('user.profile.submit');
Route::get('dashboard', 'AuthController@dashboard')->name('dashboard');
});
Route::middleware(['web', 'role:admin'])->namespace('admin')->name('admin.')->group(function()
{
Route::get('suppliers/datatable', 'SuppliersController@datatable')->name('suppliers.datatable');
Route::get('suppliers/contacts/datatable', 'SuppliersController@contacts_datatable')->name('suppliers.contacts.datatable');
Route::get('suppliers/{id}/delete', 'SuppliersController@destroy')->name('suppliers.delete');
Route::resource('suppliers', 'SuppliersController');
Route::get('rfqs/datatable', 'RfqController@datatable')->name('rfqs.datatable');
Route::get('rfqs/{id}/delete', 'RfqController@destroy')->name('rfqs.delete');
Route::resource('rfqs', 'RfqController');
Route::post('rfqs/attachments', 'RfqAttachmentsController@upload')->name('rfqs.attachments.upload');
Route::get('rfqs/attachments/{id}', 'RfqAttachmentsController@view')->name('rfqs.attachments.view');
Route::post('rfqs/attachments/delete/{id}', 'RfqAttachmentsController@delete')->name('rfqs.attachments.delete');
});
rfqs的资源路由无法正常工作,如果我尝试使用route()
函数输出链接,则会不断出现以下错误:
Route [supplier.rfqs.index] not defined
如果我执行php artisan route:list
,则可以看到已定义admin rfq资源路由,但未定义供应商路由。奇怪的是,如果我将其定义为Route::resource('rfqs', 'RfqController');
,它会起作用,但是当我希望它只是/ rfqs时,URL是/ supplier / rfqs
+--------+-----------+----------------------------------------+-----------------------------------------+------------------------------------------------------------------------+-------------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+----------------------------------------+-----------------------------------------+------------------------------------------------------------------------+-------------------+
| | POST | / | supplier.auth.login.submit | App\Http\Controllers\supplier\AuthController@handle_login | web,guest |
| | GET|HEAD | / | supplier.auth.login | App\Http\Controllers\supplier\AuthController@index | web,guest |
| | POST | admin | admin.auth.login.submit | App\Http\Controllers\admin\AuthController@handle_login | web,guest |
| | GET|HEAD | admin | admin.auth.login | App\Http\Controllers\admin\AuthController@index | web,guest |
| | GET|HEAD | admin/dashboard | admin.dashboard | App\Http\Controllers\admin\AuthController@dashboard | web,role:admin |
| | POST | admin/forgotten-password | admin.auth.forgotten_password.submit | App\Http\Controllers\admin\AuthController@handle_forgotten_password | web,guest |
| | GET|HEAD | admin/forgotten-password | admin.auth.forgotten_password | App\Http\Controllers\admin\AuthController@forgotten_password | web,guest |
| | POST | admin/forgotten-password/reset/{token} | admin.auth.reset_password.submit | App\Http\Controllers\admin\AuthController@handle_reset_password | web,guest |
| | GET|HEAD | admin/forgotten-password/reset/{token} | admin.auth.reset_password | App\Http\Controllers\admin\AuthController@reset_password | web,guest |
| | GET|HEAD | admin/logout | admin.auth.logout | App\Http\Controllers\admin\AuthController@logout | web,role:admin |
| | POST | admin/user | admin.user.profile.submit | App\Http\Controllers\admin\AuthController@update_profile | web,role:admin |
| | GET|HEAD | admin/user | admin.user.profile | App\Http\Controllers\admin\AuthController@profile | web,role:admin |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | dashboard | supplier.dashboard | App\Http\Controllers\supplier\AuthController@dashboard | web,role:supplier |
| | POST | forgotten-password | supplier.auth.forgotten_password.submit | App\Http\Controllers\supplier\AuthController@handle_forgotten_password | web,guest |
| | GET|HEAD | forgotten-password | supplier.auth.forgotten_password | App\Http\Controllers\supplier\AuthController@forgotten_password | web,guest |
| | GET|HEAD | forgotten-password/reset/{token} | supplier.auth.reset_password | App\Http\Controllers\supplier\AuthController@reset_password | web,guest |
| | POST | forgotten-password/reset/{token} | supplier.auth.reset_password.submit | App\Http\Controllers\supplier\AuthController@handle_reset_password | web,guest |
| | GET|HEAD | logout | supplier.auth.logout | App\Http\Controllers\supplier\AuthController@logout | web,role:supplier |
| | GET|HEAD | rfqs | admin.rfqs.index | App\Http\Controllers\admin\RfqController@index | web,role:admin |
| | POST | rfqs | admin.rfqs.store | App\Http\Controllers\admin\RfqController@store | web,role:admin |
| | POST | rfqs/attachments | admin.rfqs.attachments.upload | App\Http\Controllers\admin\RfqAttachmentsController@upload | web,role:admin |
| | POST | rfqs/attachments/delete/{id} | admin.rfqs.attachments.delete | App\Http\Controllers\admin\RfqAttachmentsController@delete | web,role:admin |
| | GET|HEAD | rfqs/attachments/{id} | admin.rfqs.attachments.view | App\Http\Controllers\admin\RfqAttachmentsController@view | web,role:admin |
| | GET|HEAD | rfqs/create | admin.rfqs.create | App\Http\Controllers\admin\RfqController@create | web,role:admin |
| | GET|HEAD | rfqs/datatable | admin.rfqs.datatable | App\Http\Controllers\admin\RfqController@datatable | web,role:admin |
| | GET|HEAD | rfqs/{id}/delete | admin.rfqs.delete | App\Http\Controllers\admin\RfqController@destroy | web,role:admin |
| | GET|HEAD | rfqs/{rfq} | admin.rfqs.show | App\Http\Controllers\admin\RfqController@show | web,role:admin |
| | PUT|PATCH | rfqs/{rfq} | admin.rfqs.update | App\Http\Controllers\admin\RfqController@update | web,role:admin |
| | DELETE | rfqs/{rfq} | admin.rfqs.destroy | App\Http\Controllers\admin\RfqController@destroy | web,role:admin |
| | GET|HEAD | rfqs/{rfq}/edit | admin.rfqs.edit | App\Http\Controllers\admin\RfqController@edit | web,role:admin |
| | GET|HEAD | suppliers | admin.suppliers.index | App\Http\Controllers\admin\SuppliersController@index | web,role:admin |
| | POST | suppliers | admin.suppliers.store | App\Http\Controllers\admin\SuppliersController@store | web,role:admin |
| | GET|HEAD | suppliers/contacts/datatable | admin.suppliers.contacts.datatable | App\Http\Controllers\admin\SuppliersController@contacts_datatable | web,role:admin |
| | GET|HEAD | suppliers/create | admin.suppliers.create | App\Http\Controllers\admin\SuppliersController@create | web,role:admin |
| | GET|HEAD | suppliers/datatable | admin.suppliers.datatable | App\Http\Controllers\admin\SuppliersController@datatable | web,role:admin |
| | GET|HEAD | suppliers/{id}/delete | admin.suppliers.delete | App\Http\Controllers\admin\SuppliersController@destroy | web,role:admin |
| | GET|HEAD | suppliers/{supplier} | admin.suppliers.show | App\Http\Controllers\admin\SuppliersController@show | web,role:admin |
| | PUT|PATCH | suppliers/{supplier} | admin.suppliers.update | App\Http\Controllers\admin\SuppliersController@update | web,role:admin |
| | DELETE | suppliers/{supplier} | admin.suppliers.destroy | App\Http\Controllers\admin\SuppliersController@destroy | web,role:admin |
| | GET|HEAD | suppliers/{supplier}/edit | admin.suppliers.edit | App\Http\Controllers\admin\SuppliersController@edit | web,role:admin |
| | GET|HEAD | user | supplier.profile | App\Http\Controllers\supplier\AuthController@profile | web,role:supplier |
| | POST | user | supplier.profile.submit | App\Http\Controllers\supplier\AuthController@update_profile | web,role:supplier |
+--------+-----------+----------------------------------------+-----------------------------------------+------------------------------------------------------------------------+-------------------+
答案 0 :(得分:0)
您的路由文件中已写入
Route::resource('suppliers', 'SuppliersController');
使用类似
的命名路由Route::resource('suppliers', 'SuppliersController')->name('suppliers');