I am use a form with attribute method="POST"
to update the record in laravel. But updating of record is not working. Then after putting @method('PUT')
inside the form, record updating is working fine.
I just want to know about @method('PUT')
and when to use it in form of Laravel application.
Not Working
<form action="{{ route('student.update',$studentData->id) }}" method="POST">
...
</form>
Working Fine
<form action="{{ route('student.update',$studentData->id) }}" method="POST">
@csrf
@method('PUT')
...
</form>
CodePudding user response:
What does your web.php file look like ?
If you're using Route::resource('student', SomeController::class)
POST method will hit your student.create
route, while PUT will hit your student.update
route.
You can check your routes and their respective methods in detail by running php artisan route:list
in your console
CodePudding user response:
The use of @method(...)
is called form method spoofing in Laravel and is a requirement because HTML forms do no support PUT
, PATCH
or DELETE
for the method
attribute.
The value of the @method
is sent as part of the form request and used by Laravel to determine how to process the form submission.