laravel 链接有效但按钮无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20797815/
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:48:49  来源:igfitidea点击:

laravel link does work but button does not

twitter-bootstraplaravel

提问by JeffreyR

In laravel i have link called ZOEKEN it goes to 'zoekenindex'. It works

在 laravel 中,我有一个名为 ZOEKEN 的链接,它指向“zoekenindex”。有用

  <li> {{HTML::link('zoekenindex','ZOEKEN')}}</li>

But instead of a a link i want a button:

但我想要一个按钮而不是 aa 链接:

 <button href="{{ route('zoekenindeze') }}" type="button" class="btn btn-default">Left</button>

this outputs: "Unable to generate a URL for the named route "zoekenindex" as such route does not exist."

此输出:“无法为命名路由“zoekenindex”生成 URL,因为此类路由不存在。

I don't get why, because the route works when i use the link code.

我不明白为什么,因为当我使用链接代码时该路线有效。

Anyone got a idea why this is possible?

任何人都知道为什么这是可能的?

回答by Anam

Laravel don't find any name route called zoekenindexin your route file.

Laravelzoekenindex在您的路由文件中找不到任何名称路由。

Create a name route:

创建名称路由:

Route::get('zoekenindex', array('as' => 'zoekenindex', 'uses' => 'yourController@index'))

Your button: bootstrap by default will create the button. don't worry about the link.

您的按钮:默认情况下引导程序将创建按钮。不要担心链接。

<a href="{{ URL::route('zoekenindex') }}" class="btn btn-default">Left</a>

Laravel helper:

Laravel 助手:

{{ link_to_route('zoekenindex', 'Left', null, array('class' => 'btn btn-default')) }}

or, if you don't like to create a name route, use the following:

或者,如果您不喜欢创建名称路由,请使用以下命令:

<a href="{{ URL::to('zoekenindex') }}" class="btn btn-default">Left</a>

Laravel helper:

Laravel 助手:

{{ link_to('zoekenindex', 'Left', array('class' => 'btn btn-default')) }}

回答by elliotanderson

<button href="{{ url('zoekenindeze') }}" type="button" class="btn btn-default">Left</button>

and it will point to the zoekenindeze route

它将指向 zoekenindeze 路线

回答by Harry Bosh

Laravel 5

Laravel 5

{!! HTML::linkRoute('admin.users.edit', $user->display_name, array($user->id), ['class' => 'btn btn-default']) !!}