Instead of $this->validate use Validator::make, so then you can
$validator = Validator::make($data,$rules);
if($validator->fails())
{
// do your stuff
}
Hi, I have a file upload button and a validation if the file input is empty. I'm currently using $this->validate() (component) from live-wire and jet-stream's <x-jet-validation-errors/> (blade file) to display the error on my modal. The thing is, I wanted to display the validation error on a new modal but it seems like once the validate execute an exception, I am not able to catch it to reveal the new modal and put the validation error messages on it. The process should be:
File Input -> Validation -> If Validation Fail / Has Error -> show a new modal with validation error on it.
Component
public function upload()
{
if($this->validate([
'file.*' => 'mimes:pdf|max:1024', // 1MB Max
'file' => 'required',
'documentType' => [
'required',
Rule::notIn(['Select Document Type']),
],
])){
dd("Uploading ..."); //No errors, proceed on uploading the file/s.
//Do Something ..
}else{
//Once validation has error, code does not execute on else if
//$this->modalValidationErrorVisible = true;
dd("Ooops! ((-- Validation Error Messages --))");
};
}
Blade File
<div class="mt-1 pr-4 flex rounded-md shadow-sm">
<x-jet-validation-errors class="mb-4" />
</div>
Process
Please or to participate in this conversation.