Laravel form html with PUT method for PUT routes

后端 未结 6 963
庸人自扰
庸人自扰 2020-12-05 23:09

I Have this in my routes :

+--------+---------------------------+--------------+---------------------------                                                           


        
相关标签:
6条回答
  • 2020-12-05 23:41

    in your view blade change to

    {{ Form::open(['action' => 'postcontroller@edit', 'method' => 'PUT', 'class' = 'your class here']) }}
    
    <div>
    {{ Form::textarea('textareanamehere', 'default value here', ['placeholder' => 'your place holder here', 'class' => 'your class here']) }}
    </div>
    
    <div>
    {{ Form::submit('Update', ['class' => 'btn class here'])}}
    </div>
    
    {{ Form::close() }}
    

    actually you can use raw form like your question. but i dont recomended it. dan itulah salah satu alasan agan belajar framework, simple, dan cepat. so kenapa pake raw form kalo ada yang lebih mudah. hehe. proud to be indonesian.

    reference: Laravel Blade Form

    0 讨论(0)
  • 2020-12-05 23:42

    Is very easy, you just need to use method_field('PUT') like this:

    HTML:

    <form action="{{ route('route_name') }}" method="post">
        {{ method_field('PUT') }}
        {{ csrf_field() }}
    </form>
    

    or

    <form action="{{ route('route_name') }}" method="post">
        <input type="hidden" name="_method" value="PUT">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
    </form>
    

    Regards!

    0 讨论(0)
  • 2020-12-05 23:45

    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() }}
    

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

    Note: Since HTML forms only support POST and GET, PUT and DELETE methods will be spoofed by automatically adding a _method hidden field to your form. (Laravel docs)

    <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>
    
    0 讨论(0)
  • 2020-12-05 23:46

    If you are using HTML Form element instead Laravel Form Builder, you must place method_field between your form opening tag and closing end. By doing this you may explicitly define form method type.

    <form>
    {{ method_field('PUT') }}
    </form>
    
    0 讨论(0)
  • 2020-12-05 23:52
    <form action="{{url('/url_part_in_route').'/'.$parameter_of_update_function_of_resource_controller}}"  method="post">
    @csrf
    <input type="hidden" name="_method" value="PUT">    //   or @method('put')          
    ....    //  remained instructions                                                                              
    <form>
    
    0 讨论(0)
  • 2020-12-05 23:57

    Just use like this somewhere inside the form

    @method('PUT')
    
    0 讨论(0)
提交回复
热议问题