Thursday, March 16, 2017

Add a validation which is not related to the form

I want to add a validation on a form. My actual form works, here it is:

public function store(Request $request, $id)
{
    $this->validate($request, [
        'subject' => 'required',
        'body' => 'required',
    ]);

    // Do something if everything is OK.
}

Now, I want to check if the user is "active" too. So something like:

\Auth::user()->isActive();

And return an error with the other validation errors if the user is not active.

Can I append something to the validator that has no relation with the form itself? I mean I want to add an error to the other errors if the user is not active.



via rap-2-h

Advertisement