protected function validator(array $data)
{
$validation = Validator::make($data, [
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed']
]);
if ($validation->fails())
{
return session()->flash('alert-danger', 'error');
}
}
protected function create(array $data)
{
$company = new Company();
$company->store_name = $data['company_name'];
$company->save();
}
Check the fail status inside the validator function and show the error message
3
Answers
try this below code instead of the above validation
now if you remove the code
the code will run without any error .
and if you do not enter any value in the input field
the the request->validate() will check all the request.
You need to actually return something in your
if ($validation->fails())
check. Right now, you’re setting a session Flash, but returningnull
(->flash()
has no return value).You have a couple solutions here, but it depends if this is a Form Submission or an AJAX Request:
Basically, modify your
validator
method to return theValidator::make()
instance, check it in yourcreate()
method, and return appropriately based on if this is an AJAX Request or Form Submission.