Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Blade template Form::open() to Html

I am following a tutorial about Laravel.

However, I want to convert the blade template Form::open() to html/php form, to make it easier to read & understand.

This is the Blade template:

   {{ Form::open(['action'=> ['StudentController@destroy', $student->id], 'method'=>'POST']) }}
            {{ method_field('DELETE') }}
            {{ Form::submit('Delete',['class'=>'btn btn-danger']) }}
   {{ Form::close() }}

I need to convert the blade code to html/php I tried it multiple times, something like this. but failed.

    <form action="url('StudentController@destroy', $student->id)" method="POST">
        <?php method_field('Delete'); ?>
        <button class="btn btn-danger" type="submit">Delete</button>
    </form>

Anyone know the correct html/php form?

[edit] Route:list enter image description here

like image 810
Evan Avatar asked Sep 17 '25 14:09

Evan


2 Answers

try this way

use {{}} and use route

 <form action="{{route('StudentController@destroy', ['id'=>$student->id])}}" method="POST">
    <?php method_field('Delete'); ?>
    <button class="btn btn-danger" type="submit">Delete</button>
</form>
like image 199
Bhargav Chudasama Avatar answered Sep 20 '25 04:09

Bhargav Chudasama


To call a controller action you need to use url()->action(...) (or action()) for short.

<form action="{{url()->action('StudentController@destroy', ['id'=>$student->id])}}" method="POST">
    @csrf
    {{ method_field('DELETE'); }}
    <button class="btn btn-danger" type="submit">Delete</button>
</form>

This is also described in the manual

like image 25
apokryfos Avatar answered Sep 20 '25 05:09

apokryfos