mercredi 12 juin 2019

automatically failing custom request in laravel

I have created a custom request that needs to check a variable before proceeding forward. This is my CustomRequest and have something like this

class CustomRequest extends FormRequest
{

    public function rules(){
        if ($variable == "abc") {
            return [
                "method"             => [
                    "required",
                    "in:mail",
                ]
            ];
        }
    }

}

And in my controller it is

public function addMethod(CustomRequest $request)
{
    //
}

I want that if the $variable is not equal to abc it just automatically fails and redirects the user back with message. I don't know how to do that.

Is there any possibility to achieve such functionality?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire