简体   繁体   English

Laravel带有路线别名的表单帮助器

[英]Laravel Form helper with route alias

I create a from to send a DELETE method to server, the code looks like this: 我创建了一个from,将DELETE方法发送到服务器,代码如下所示:

{Form::open('company/'.$company->id, 'DELETE', array('style'=>'display: inline'))}}
      {{Form::hidden('id', $company->id)}}
      {{Form::submit('Delete')}}
{{Form::close()}}

However I already created an alias for this delete route, looks like bellow: 但是,我已经为此删除路由创建了一个别名,如下所示:

Route::get('company/(:num)',array('as' => 'delete_company', 'uses'=>'company@destroy'));

How do I use the alias in this case instead of explicitly write it out as above? 在这种情况下,我该如何使用别名而不是像上面那样明确地将其写出?

If you mean to ask on how to get the URL to that named route, here is what you need to do in L3 如果您想询问如何将URL转到该命名路由,则这是在L3中需要执行的操作

$url = URL::to_route('delete_company', array($company->id));
Form::open($url);

I am not sure if you can do a DELETE http request with a form, as forms only support POST and GET, you may need to use a javascript library like Angularjs, backbone or jquery. 我不确定是否可以使用表单执行DELETE http请求,因为表单仅支持POST和GET,因此您可能需要使用Angularjs,boneer或jquery之类的JavaScript库。 It seems this is possible in Laravel, see the comment below :) 在Laravel中似乎有可能,请参见下面的评论:)

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

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