Laravel 链接到控制器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21465015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:56:27  来源:igfitidea点击:

Laravel link to Controller

phplaravellaravel-4

提问by DolDurma

i have this menu item such as :

我有这个菜单项,例如:

<li><a href="{{ URL::route('profile') }}"> Profile Managment </a></li>

and i want to route that to ProfileController. this below my route do not work.

我想把它路由到ProfileController. 这在我的路线下面不起作用。

Route::resource('profile' , 'ProfileController' , array('as'=>'profile' , 'before'=>'csrf'));

i want to route that if user can login and can see profile page and that nust be send all Request to ProfileController.

我想路由,如果用户可以登录并且可以看到个人资料页面,并且必须将所有请求发送到 ProfileController。

Error Result:

错误结果:

Error in exception handler: Route [profile] not defined. (View: /var/www/laravel/app/views/back_end/menu.blade.php) (View: /var/www/laravel/app/views/back_end/menu.blade.php) (View: /var/www/laravel/app/views/back_end/menu.blade.php) in /var/www/laravel/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:207

回答by The Alpha

Actualy Laravelwill create following routes

实际上Laravel将创建以下路线

Route(URL)                                      | Name
------------------------------------------------------------------
GET profile                                     | profile.index
GET profile/create                              | profile.create
POST profile                                    | profile.store
GET profile/{profile}                           | profile.show
GET profile/{profile}/edit                      | profile.edit
PUT profile/{profile}                           | profile.update
PATCH profile/{profile}                         |
DELETE profile/{profile}                        | profile.destroy

For this

为了这

Route::resource('profile' , 'ProfileController' , array('as'=>'profile' , 'before'=>'csrf'));

If you run php artisan routesfrom your terminal/command prompt then you'll get all the route's list with nameand url.

如果您php artisan routes从终端/命令提示符运行,那么您将获得带有name和 的所有路由列表url

回答by Antonio Carlos Ribeiro

Probably you'll have to:

可能你必须:

<li><a href="{{ URL::route('profile.index') }}"> Profile Managment </a></li>

To be sure, execute

可以肯定的是,执行

php artisan routes

Laravel will show the list of routes and names you have to use.

Laravel 将显示您必须使用的路由和名称列表。

Also, you have access to more info in the docs: http://laravel.com/docs/controllers#resource-controllers

此外,您可以访问文档中的更多信息:http: //laravel.com/docs/controllers#resource-controllers