简体   繁体   English

Laravel 5.7使用某些名称空间的资源控制器路由名称是什么?

[英]Laravel 5.7 what is the Resource Controller route names using some namespaces?

After upgrade to Laravel 5.7, I was using using route:resource for CRUD in Admin And the namespace is Admin. 升级到Laravel 5.7后,我在Admin中将route:resource用于CRUD,名称空间为Admin。 So for example UsersController, the route name for create is 因此,例如,对于UsersController,创建的路由名称为

route('admin.users.create')

But It doesn't work for me in Laravel 5.7. 但是在Laravel 5.7中它对我不起作用。 Also I can't use the command 我也不能使用命令

php artisan route:list

because it display an error in connection, although I use a proper connection params in .env file. 因为它显示了连接错误,尽管我在.env文件中使用了正确的连接参数。

Namespace doesn't change a route name, only defines a namespace where app will look for a controller. 命名空间不会更改路由名称,仅定义应用程序将在其中查找控制器的命名空间。

You should add route name prefix ->name('admin.') to your admin route group. 您应该将路由名称前缀->name('admin.')到您的admin路由组中。

Assign name in routes->web.php: name('admin.users.create'); 在route-> web.php中分配名称: name('admin.users.create'); like that. 像那样。

Route::get('/user', 'UserController@create')->name('admin.users.create');

Then use it in your controller ,view or model 然后在您的控制器,视图或模型中使用它

route('admin.users.create') . route('admin.users.create')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM