1101 0 0 0
Last Updated : 2024-04-19 18:46:24
In case you wanetd to change the error message of a validation rule in Laravel you can make use of the following snippet.
//Validation
$messages = [
'fullTextPDF.mimes' => 'only PDF files are allowed.',
];
$validator = Validator::make($request->all(), [
'bill_id' => 'required',
'fullTextPDF' => 'mimes:pdf',
], $messages);
$errors = $validator->errors();
Also if we need to add a custom error message to the validation message here is a sample code that might help:
$validator = Validator::make(\Request::all(), [
'description' => 'required',
'priority' => 'required',
'status' => 'required',
'duedate' => 'required',
]);
$validator->getMessageBag()->add('email', 'Email not found');
$validator->errors()->add('field', 'Something is wrong with this field!');
$errors = $validator->errors();
if ($validator->fails())
{
return redirect()->back()->withErrors( $errors );
}