@Seydina In your request file you can try adding method to handle messages
public function messages()
{
return [
'picture.max' => 'The picture must not be greater than :max kilobytes.',
];
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, when I upload file to update my profile picture all validation rules (image, mimes) works fine except one : max:3072. It show me this default message in this screenshot below when I try to upload an image greater than 3MB:
upload_max_file is set to 10MB in php.ini
My validation rules in the ProfileUpdateRequest :
<?php
namespace App\Http\Requests;
use App\Models\User;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class ProfileUpdateRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
*/
public function rules(): array
{
return [
'name' => ['string', 'max:255'],
'email' => ['email', 'max:255', Rule::unique(User::class)->ignore($this->user()->id)],
'picture' =>['image', 'mimes:jpg,jpeg,png,gif', 'max:3072'],
];
}
}
And the ProfileController code :
<?php
namespace App\Http\Controllers;
use App\Http\Requests\ProfileUpdateRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\View\View;
use App\Models\User;
use Illuminate\Validation\Rules\File;
class ProfileController extends Controller
{
/**
* Display the user's profile form.
*/
public function edit(Request $request): View
{
return view('profile.edit', [
'user' => $request->user(),
]);
}
/**
* Update the user's profile information.
*
*/
public function update(ProfileUpdateRequest $request): RedirectResponse
{
$request->user()->fill($request->validated());
if ($request->user()->isDirty('email')) {
$request->user()->email_verified_at = null;
}
$this->validate($request, [
'picture' => 'image|mimes:png,gif|max:3072',
]);
if ($request->hasFile('picture')) {
// Handle updating the user's picture as you did in the 'store' method
$path = $request->file('picture')->storePublicly('pictures');
$request->user()->picture = $path;
}
$request->user()->save();
return Redirect::route('profile.edit')->with('status', 'profile-updated');
}
/**
* Delete the user's account.
*/
public function destroy(Request $request): RedirectResponse
{
$request->validateWithBag('userDeletion', [
'password' => ['required', 'current_password'],
]);
$user = $request->user();
Auth::logout();
$user->delete();
$request->session()->invalidate();
$request->session()->regenerateToken();
return Redirect::to('/');
}
}
I want to target this default message The picture failed to upload and customize it. After reading laravel docs about custom validation I publish lang directory with php artisan lang:publish. After that I found in lang/en directory a file validation.php in which I found this message : 'uploaded' => 'The :attribute failed to upload.',. How should we do so that the message The picture failed to upload become 'The picture must not be greater than 3072 kilobytes.'?
Please or to participate in this conversation.