Маршрут ресурса Laravel 5.7 не определен - PullRequest
0 голосов
/ 16 января 2019

У меня определены следующие маршруты:

    // 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, вы увидите, что маршруты ресурса rfq администратора определены, а маршруты поставщика - нет. Странно это работает, если я определил это как Route::resource('rfqs', 'RfqController');, но тогда URL будут / supplier / rfqs, когда я хочу, чтобы это было просто / 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 |
+--------+-----------+----------------------------------------+-----------------------------------------+------------------------------------------------------------------------+-------------------+

1 Ответ

0 голосов
/ 16 января 2019

в вашем файле маршрута вы пишете

Route::resource('suppliers', 'SuppliersController');

использовать именованный маршрут как

Route::resource('suppliers', 'SuppliersController')->name('suppliers');
...