Here is my code:
public function store(Request $request){
$this->validate($request, [
'name' => 'required',
'email' => 'required|email',
'content' => 'required|min:10',
]);
$new_array = array();
$new_array['name'] = $request->name;
$new_array['email'] = $request->email;
$new_array['content'] = $request->content;
contact::create($new_array);
return back();
}
Now I need to set some new error-messages for those filters (ex: required
, email
, ..).
Currently, this is the default error message for required
:
The name field is required.
How can I change it?
Crate rules
public function user_registration_rules(array $data)
{
$messages = [
'full-name.required' => 'Please enter full name',
'address.required' => 'Please enter address'
];
$validator = Validator::make($data, [
'full-name' => 'required|min:5|max:70',
'address' => 'required'
], $messages);
return $validator;
}
Use in controller like this
$validator = $this->user_registration_rules($request_data);
if($validator->fails())
{
return redirect()->back()->withErrors($validator)->withInput();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With