gpt4 book ai didi

Laravel 6.0 如何使用路由 :resource get route same folder controller

转载 作者:行者123 更新时间:2023-12-04 19:25:32 24 4
gpt4 key购买 nike

我有问题,但在文档中找不到解决方案

我使用命令

php aritsan make:controller Backend\ProductController --resource --Model=Model\Product

所以,我需要路由相同的位置文件 Controller

我用
Route::resource('/backend/product','Backend\ProductController');

之后,运行命令
php artisan route:list

这个结果
enter image description here

但是,我不需要这个
我认为应该是
+--------+-----------+----------------------------------+-----------------+------------------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+----------------------------------+-----------------+------------------------------------------------------------+------------+
| | GET|HEAD | backend/product | backend.product.index | App\Http\Controllers\Backend\ProductController@index | web |
| | POST | backend/product | backend.product.store | App\Http\Controllers\Backend\ProductController@store | web |
| | GET|HEAD | backend/product/create | backend.product.create | App\Http\Controllers\Backend\ProductController@create | web |

路由名称应该是 backend.product.index
我找到了解决办法。但不开心。
Route::resource('/backend/user','Backend\UserController')->names([
'index' => 'backend.user.index',
'store' => 'backend.user.store',
'edit' => 'backend.user.edit',
'update' => 'backend.user.update',
'destroy' => 'backend.user.destroy',
]);

Documents resource names

最佳答案

用于创建 带资源的模型 Controller

php aritsan make:controller Backend\ProductController --resource --Model=Model\Product

Web.php 文件使用 prefix , namespace , as
Route::group(['prefix' => 'backend','namespace'=>'Backend','as'=>'backend.'], function () {
Route::resource('product','ProductController');
});

现在使用
**php artisan route:list**

backend.product.index

backend.product.create

backend.product.show

backend.product.destroy

backend.product.update

backend.product.edit

关于Laravel 6.0 如何使用路由 :resource get route same folder controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58301895/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com