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
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>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With