A
A
Alexey Sklyarov2018-09-07 12:12:53
Laravel
Alexey Sklyarov, 2018-09-07 12:12:53

How to properly validate an invite when registering a user?

There is a registration controller with a method:

public function register(Request $request)
    {
        $this->validator($request->all())->validate();

        $invite_avaible = \App\Invite::isAvailable($request->input('invite'););

        if ($invite_avaible) {
          $user = $this->create($request->all());
        }

        return $this->registered($request, $user)
                        ?: redirect($this->redirectPath())->with('success', 'We have sent an activation link on your email id. Please verify your account.');
    }

In this method, the invite is also checked for existence and possibility of use:
$invite_avaible = \App\Invite::isAvailable($request->input('invite'));

The question is how to properly validate so that you can display your own error like: "Invite is not valid", "Invite does not exist"?
I study the documentation, it would be convenient to do this in the Validator, but as far as I understand, it is not very flexible in its settings.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2018-09-07
@0example

it would be convenient to do this in the Validator, but as far as I understand, it is not very flexible in its configuration.

https://laravel.com/docs/5.6/validation#custom-val...
That is, you can use your own class that implements the interface Illuminate\Contracts\Validation\Rule,
you can use anonymous,
you can use extension

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question