Laravel Multi-user Custom Email verification

As we all know that Laravel ships in with default email verification mechanism, but there are some cases where one would need to go the custom way. For instance, when building a multiple authentication system where you have several user types, in such case, if you go by the default you would have to battle several caveats or configurations, which might take a little of your actual deadline.
NOTE:You need a solid knowledge of PHP, Laravel, to understand this article.
What is email verification? Email verification is the process of checking the viability of a user’s or registrant’s email address.
Why do need to verify emails? Sometimes, you might be wandering the essence of email verification. Let me ask you a question. What happens if you need to reach out to your users and you find out the submitted emails are invalid. Or, more importantly, what happens when a user forgets his/her password and the system sends a password recovery link to an invalid or wrong email address. In the latter case, the user might be locked out of your system forever unless there are other means like phone numbers(which might be more cost effective) and a good technical support team(which might be too late if the user gets frustrated).
Let’s grab our IDEs. We are going to use the default VerificationController file that Laravel ships by default. In this this controller, we are going to write a simple generic method that can be used to verify as many user types/models as you have in your application. But before this controller’s job, the user must have done some kind of successful registration. So, we are going to have a simple method in a UserController to register and send an email verification link. We are also going to have a user migration.
Then, in our user controller, we have our register method
This method simply creates a user and send an email verification link. you would notice a verification_code as part of the associative array in Ueser::create static method. This is where we are going to store a random unique token that would be decoded(feel free to encode and the decode with any mechanism of your choosing) during verification to avoid any malicious acts from users. You might also notice a mailable class ( App\Mail\verification), which is used for sending HTML emails. You might have to read the docs to understand laravel mailables.
Below is our route file.
Let’s write the VerifyEmail method in the Verification controller
From the above method, the $user_type parameter is nullable, but would be useful in cases where there are multiple users or authentication guards. The method first decodes each parameter, then checks if $user_type is set. If $user_type exists, it uses eloquent to check if the link is valid and the user actually exists, by setting an email verified flag to true or false.
Then in your views, you can then get the flag and print the appropriate message(e.g Email has been verified successfully). The TDD and vue js version would be up soon.
I hope I have been able to help someone. Happy coding.
