简体   繁体   中英

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?. 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

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

Here is my HTML form code:

<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?

You can't do model binding directly into 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).

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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