php – How to validate that a parameter is an instance of a given class in Laravel?-ThrowExceptions

Exception or error:

What json should I pass in request to pass this validation?
Here is the document:

Enum instance
Additionally you can validate that a parameter is an instance of a given enum.

use BenSampo\Enum\Rules\Enum;

public function store(Request $request)
{
    $this->validate($request, [
        'user_type' => ['required', new Enum(UserType::class)],
    ]);
}

and here is the code

public function passes($attribute, $value)
{
    return $value instanceof $this->enumClass;
}

https://github.com/BenSampo/laravel-enum

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *