When uploading files you need to add this to the form tag
enctype="multipart/form-data"
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, i'm struggling with a form post request. i'm using laravel 9.45 and php 8.1.12
This is the form file i have text input and a file input
<form method="POST" action="{{ route('update_profile', Auth::user() ) }}">
@csrf
This is the web file
Route::put('/{user}/profile/update', 'update')->name('update_profile');
and this is in the controller ( i haven't finished writing this)
public function update(Request $request, User $user)
{
$request->validate([
'name' => ['nullable', 'string', 'max:255'],
'company' => ['nullable','string', 'max:255'],
'vat' => ['nullable', 'string', 'max:15'],
'email' => ['nullable', 'string', 'email', 'max:255', 'unique:users'],
'avatar' => ['nullable', 'mimes:jpg,png,jpeg', 'max:2048'],
]);
dd($request->all());
$avatar = null;
if($request->hasFile('avatar')){
$avatar = $request->file('avatar')->store('/users/avatar', 'public');
}
$user->update([
'name' => $request['name'],
'company' => $request['company'],
'vat' => $request['vat'],
'avatar' => $avatar,
]);
return route('edit', $user);
}
it works fine but, the request go in the controller and does the thing, BUT only when i try to upload an image the validator method i guess doesn't validate properly and i get this error:
The 1/profile/edit method is not supported for route GET. Supported methods: POST.
and the request:
upload : 302
edit: 405
If i go back to the edit page, the file input displays the error even tho my file is a png image.
i run the cache reset and route cache command, but nothing.
how can i solve this?
When uploading files you need to add this to the form tag
enctype="multipart/form-data"
Please or to participate in this conversation.