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.
Related
I was watching an old tutorial about laravel 7 whiles using laravel 9, i tried to create a HTML form like this.
<div class="card-body">
<form action="/upload" method="post" enctype="multipart/form-data">
#csrf
<input type="file" name="image">
<input type="submit" value="upload">
</form>
</div>
then in my route(web.php) i added a code like this
route::post('/upload', function(Request $request)
{$request->image->store('images', 'public');
return 'image uploaded succesfully';
but in my webiste it tells me page the url you requested is not found on the site serve
You've defined your route using POST meaning it will only respond to POST requests.
If you try to access /upload from a web browser, that uses a GET request which you've not defined a route for. So you want to define such a route:
Route::get('/upload', function () {
return view('upload.blade.php');
});
You'll want to replace upload.blade.php with the name of your view that has your upload form in it.
Name Your Route 1st , hit this command php artisan route:clear then try..
Change the form action action="{{ route('upload') }}"
<div class="card-body">
<form action="{{ route('upload') }}" method="post" enctype="multipart/form-data">
#csrf
<input type="file" name="image">
<input type="submit" value="upload">
</form>
</div>
i want to submit for updating the data, i already use the patch method, but it keep telling me that the get method is not supported
the edit formedit.info.blade
<form action="{{ route('info.update', ['info' => $info->id]) }}" method="patch" enctype="multipart/form-data">
<input type="hidden" name="_method" value="patch">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
the route list
web.php
//info penting
route::get('/info-admin','InfosController#index')->middleware('auth','admin')->name('admin.info-admin');
route::get('/tambah-info','PagesController#tambah')->middleware('auth','admin')->name('info.add');
route::patch('/update-info/{info}/update','InfosController#update')->name('info.update');
route::get('/edit-info/{info}/edit','InfosController#edit')->middleware('auth','admin')->name('info.edit');
route::delete('/info/{id}','InfosController#destroy')->middleware('auth','admin')->name('info.destroy');
here's for update logic
InfosController
public function update(Request $request, Info $info) {
Info::where('id', $info->id)->update([
'judul' => $request->judul,
'konten' => $request->konten,
'image' => $request->image,
]);
return redirect('')->route('admin.info-admin')->with('success', 'Successful');
}
what did i do wrong?
HTML5 forms only supports GET, POST and DIALOG method only. so using PATCH won't work.
you have to add it inside the from
<form action="{{ route('info.update', ['info' => $info->id]) }}" method="POST" enctype="multipart/form-data">
#csrf
#method('PATCH')
this link will help you to understand form methods.
You have to change the method to POST. Because in some browser PUT/PATCH is not suported
<form action="{{ route('info.update', ['info' => $info->id]) }}" method="post" enctype="multipart/form-data">
<input type="hidden" name="_method" value="patch">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
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"/>
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">
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()
{
//
});