Laravel表单HTML和PUT方法进行PUT路由

Laravel表单HTML和PUT方法进行PUT路由

本文介绍了Laravel表单HTML和PUT方法进行PUT路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的路线上有这个东西:

I Have this in my routes :

+--------+---------------------------+--------------+---------------------------                                                                                                                ---------+----------------+---------------+
| Domain | URI                       | Name         | Action                                                                                                                                             | Before Filters | After Filters |
+--------+---------------------------+--------------+---------------------------                                                                                                                ---------+----------------+---------------+
|        | GET|HEAD /                |              | postcontroller                                                                                                                                     | auth           |               |
|        | GET|HEAD login            |              | homecontroller@dologin                                                                                                                             |                |               |
|        | POST login                |              | homecontroller@dologin                                                                                                                             |                |               |
|        | GET|HEAD logout           |              | homecontroller@dologout                                                                                                                            |                |               |
|        | GET|HEAD post             | post.index   | postcontroller@index                                                                                                                               |                |               |
|        | GET|HEAD post/create      | post.create  | postcontroller@create                                                                                                                              |                |               |
|        | POST post                 | post.store   | postcontroller@store                                                                                                                               |                |               |
|        | GET|HEAD post/{post}      | post.show    | postcontroller@show                                                                                                                                |                |               |
|        | GET|HEAD post/{post}/edit | post.edit    | postcontroller@edit                                                                                                                                |                |               |
|        | PUT post/{post}           | post.update  | postcontroller@update                                                                                                                              |                |               |
|        | PATCH post/{post}         |              | postcontroller@update                                                                                                                              |                |               |
|        | DELETE post/{post}        | post.destroy | postcontroller@destroy

现在,我想制作一个将使用PUT方法的表单html.这是我的代码:

Now, i want to make a form html that will use PUT method. Here it is my codes:

<form class="col-md-12" action="<?php echo URL::to('/');?>/post/<?=$post->postID?>" method="put">
    <div class="form-group">
        <textarea type="text" class="form-control input-lg" placeholder="Text Here" name="post"><?=$post->post?></textarea>
    </div>
    <div class="form-group">
        <button class="btn btn-primary btn-lg btn-block" type="submit" value="Edit">Edit</button>
    </div>
</form>

但是我无法将表单提交到post.edit中.

But i doesn't work to submit the form into post.edit.

我已经用谷歌搜索了,并且找到了必须使用的解决方案

I Have googled and i got solution that i must use

{{form:...etc

但是,我希望表单仍然可以通过CSS样式完成.有什么解决方案的人吗?谢谢

But, i want the form still can done by CSS styling.Is there any solution guys?Thank You

推荐答案

您可以添加css clase以及需要使用刀片模板的任何类型的属性,请尝试以下操作:

You CAN add css clases, and any type of attributes you need to blade template, try this:

{{ Form::open(array('url' => '/', 'method' => 'PUT', 'class'=>'col-md-12')) }}
.... wathever code here
{{ Form::close() }}

如果您不想走刀路,可以添加一个隐藏的输入.这是Laravel采取的任何形式:

If you dont want to go the blade way you can add a hidden input. This is the form Laravel does, any way:

<form class="col-md-12" action="<?php echo URL::to('/');?>/post/<?=$post->postID?>" method="POST">

<!-- Rendered blade HTML form use this hidden. Dont forget to put the form method to POST -->

<input name="_method" type="hidden" value="PUT">

<div class="form-group">
    <textarea type="text" class="form-control input-lg" placeholder="Text Here" name="post"><?=$post->post?></textarea>
</div>
<div class="form-group">
    <button class="btn btn-primary btn-lg btn-block" type="submit" value="Edit">Edit</button>
</div>
</form>

这篇关于Laravel表单HTML和PUT方法进行PUT路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 04:35