I want to pass the value of the current field to a custom validation function in a Request class in my Laravel project.
I have tried the following:
public function rules()
{
return [
'id'=>'required',
//'type'=>'required|in:Attachment,Audio,Book,Picture,Video',
'type'=>['required', $this->validateFileType()],
//'type'=>[new Enum(FileType::class)], # only available on PHP 8.1+
'soft_price' => 'numeric|min:1000',
'hard_price' => 'numeric|min:1000',
];
}
public function validateFileType($type){
$file_types = ['Attachment', 'Audio', 'Book', 'Picture', 'Video'];
if(in_array($type, $file_types))
return true;
else
return false;
}
and I get the following error:
"Too few arguments to function App\\Http\\Requests\\FileUpdateRequest::validateFileType(), 0 passed in C:\\xampp\\htdocs..."
How do I do it?