简体   繁体   English

通过 HTML 语法绑定 Laravel 表单模型

[英]laravel form model binding through HTML syntax

I am using blade template but i was to know that is there any way to use form binding on html syntax based form?.我正在使用刀片模板,但我知道有什么方法可以在基于 html 语法的表单上使用表单绑定? if i would do it in blade's way it would be like如果我用刀片的方式来做它会像

{{ Form::model( $user, array('route' => array('users.update', $user->id), 'method' => 'put' )) }} But what if i want to use it like we add a hidden field for csrf_token() like {{ Form::model( $user, array('route' => array('users.update', $user->id), 'method' => 'put' )) }}但是如果我想怎么办使用它就像我们为csrf_token()添加一个隐藏字段一样

<input type="hidden" name="_token" value="{{ csrf_token() }}" />

Here is my HTML form code:这是我的 HTML 表单代码:

<form class="form-group" action="/update" method="post" id="EditCommunityForm">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="text" name="community_name" class="form-control">
</form>

Edit:编辑:

i would like to ask that is there a way to convert this syntax {{ Form::model( $user, array('route' => array('users.update', $user->id), 'method' => 'put' )) }} to plain HTML?我想问一下有没有办法转换这个语法{{ Form::model( $user, array('route' => array('users.update', $user->id), 'method' => 'put' )) }}到纯 HTML?

You can't do model binding directly into html.您不能直接将模型绑定到 html 中。 You'll have to fill your form "manually".您必须“手动”填写表格。 And, in your case, we will have to do a trick to overwrite the browser default methods (post/get).而且,在您的情况下,我们将不得不做一个技巧来覆盖浏览器默认方法(post/get)。

Heres an example:这是一个例子:

<form action="{{ route('users.update', $user->id) }}" method="post">

    <!-- Overwrite post method as 'Put' -->
    <input type="hidden" name="_method" value="PUT"/>

    <!-- CSRF token -->
    <input type="hidden" name="_token" value="{{ csrf_token() }}">

    <!-- Fills an input with a model value -->
    <input type="text" name="community_name" value="{{ $user->community_name }}"/>

</form>

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

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