Laravel 5.8 #csrf and #method not working - laravel

When using the #csrf and the #method('') it shows correctly on the page code but doesn't work. Either fails with 419 error code or the original method isn't allowed for this page type error.
Using the "old" code seems to work
#csrf
{{ csrf_field() }}
#if(isset($post))
#method('PUT')
{{method_field('PUT')}}
#endif
The csrf_field and method_field options work even though they show the same values in the page code.
<input type="hidden" name="_token" value="hTLipJaANmyR2I9VPyF7QvUKDiQlte7BAoRLjqeN">
<input type="hidden" name="_token" value="hTLipJaANmyR2I9VPyF7QvUKDiQlte7BAoRLjqeN">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_method" value="PUT">

Related

Call to undefined function method_field()

I have created a view for lumen with this code:
<form action="{{ route('extentions.update', ['id'=>$extention->id]) }}" class="form" method="POST">
#method('PUT')
#include('extentions._partials.form')
<button type="submit">Enviar</button>
</form>
However i am getting the error Call to undefined function method_field() when opening this view, does Lumen not have the #method function? If so, what should I do?
Using <input type="hidden" name="_method" value="PUT"> instead of #method('PUT') worked.

Laravel datatables raw columns

i have a code like this to display an action button for datatables
->addColumn('action', function () {
return '<form id="delete" action="{{ route(' . 'admin.posts.destroy' . ', $model) }}" method="POST">
#csrf
#method("DELETE")
Edit
<input type="submit" class="btn btn-danger" value="Delete">
</form>';
})
But the #csrf and #method("DELETE") become a string/text (not method). I tried to append {{ }} in #csrf and #method("DELETE") but it doesn't work. How to change that text to method in blade templates without make a new view for action button like that?
Thank you!
#csrf replace with <input type="hidden" name="_token" value="{{ csrf_token() }}"> and
#method("DELETE") with <input type="hidden" name="_method" value="delete">

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException The GET method is not supported for this route. Supported methods: PUT

view
web.php
[productsController
Change your web.php file
Route::post('/update/{id}','productsController#update')->name('product.update');
In your view
<form action="{{route('product.update',['id' => $products->id])}}" method="post">
Replace #method('PUT') with
<input name="_method" type="hidden" value="PUT">
Remove method="PUT" and place method="POST" from <form ...> tag. Also, I'm not sure about this #method('PUT'). I will use something like this: <input type="hidden" name="_method" value="PUT"/>

MethodNotAllowedHttpException Laravel method PUT not working

Basically I am using modal-dialog as shown below and I'm trying to get the method PUT to work. Unfortunately, I've tried either ways with _method="PUT" but it still doesn't work, anyone has a solution for this?
<div class="modal-body">
<form class="form-horizontal" role="form" method="POST" _method="PUT" action="/manage_accounts/{{ $user->id }}" novalidate>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
The problem is that HTML does not support PUT methods natively so you can't do something like this:
<form method="PUT"...
There is a workaround for this. Laravel accepts PUT, PATCH, and DELETE methods by adding a hidden input field. In other words, something like this:
<form class="form-horizontal" role="form" method="POST" action="/manage_accounts/{{ $user->id }}" novalidate>
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
Notice that you are POSTing to the server, but you can add a hidden input field named _method for PUT, PATCH, and DELETE methods.
You are probably PUTting to a GET route.
Make sure that the '/manage_accounts/{id}' route is setup as a PUT in your routes file.
Route::put('/manage_accounts/{id}', function()
{
//
});

Laravel Use of undefined constant in form

Hello so I am a beginner in laravel and having some problems. I am not using Illuminate html for my forms because I want just plain html forms. I'm getting this Use of undefined constant id - assumed 'id' in my edit.blade.php. Here is my edit.blade.php:
<form action="/books/{{$book.id}}/update" method="POST">
Title: <input type="text" name="title"> <br/>
Author: <input type="text" name="author"> <br/>
ISBN: <input type="text" name="isbn"> <br/>
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="submit">
</form>
And in my controller:
public function getBook($id) {
$book = Books::findOrFail($id);
return view('books.edit', compact('book'));
}
Am I doing something wrong?
Ok so I fixed it by myself.
First thing is I changed the line {{$book.id}} to {{$book->id}}.
Second is to edit .env with this values:
CACHE_DRIVER=array
SESSION_DRIVER=cookie
QUEUE_DRIVER=array
Then restart server php artisan serve.

Resources