my problem : i am using laravel framework php
i want validate a field witch my field sometime is File(image) and sometime is String(src of same image)
is there any shortcut or solution in Laravel ???
The specifics of your question are not exactly clear but I think you can manage what you want by doing something like:
$request->validate([
'stringOrFile' => [
function ($attribute, $value, $fail) {
if (!is_string($value) && !($value instanceof UploadedFile)) {
$fail('The '.$attribute.' must either be a string or file.');
}
}
]
]);
Where UploadedFile
refers to \Illuminate\Http\UploadedFile
and stringOrFile
refer to the name of the input your are validating.
However if possible use a different name for the input depending on what it is so you can have more complex validation rules on each different input.
More details on these kinds of validation rules in the manual