Member-only story

A full-featured multi-tenant app with Laravel Part 3 — Invitation.

4 min readJan 13, 2018
Photo by rawpixel.com

Part 0, Part 1, Part 2, Part3 👇, Part4, Part 5, Part 6, Part 7

In this part of writing a complete Laravel multi-tenant app series, we’ll accomplish the following tasks:

✅ Create a token and notify the admin via an email

✅ Create a page for setting a password

Right now when we create an admin for a new tenant, we auto assign a random password for the account and print it out so that the admin can login using this password. This is okay, maybe, for an MVP but it is a little weird for a real app and because we are really building a real app, this isn’t okay.

So, instead of printing out the password, we’ll email the admin an invitation to let her know that a tenant is created and she can set a new password for her account.

Sending an email with Laravel is as easy as it gets but how do we actually do the actual management of invitations? We have few things to worry about — setting up the proper tables, creating secure tokens, verifying the token and making sure it is actually linked to the proper admin, adding UI etc. That’s a lot of code for and looks intimidating!

But Laravel already comes with (almost) all the code for handling this albeit under a different name — Password Resets. Let’s see how we can use this feature with a little code of our own to make it happen without writing everything on our own.

1. Create a token and notify the admin via an email

We have to create a self-expiring token in the database using PasswordBroker class first and email this token to the user. Let’s create TenantCreated notification class that is responsible for notifying the admin user. You can use an artisan command to quickly create the bare-bone class:

php artisan make:notification TenantCreated

Nothing too magical here if you are already familiar with Laravel Notifications — we…

--

--

Ashok Gelal
Ashok Gelal

Written by Ashok Gelal

Learner. Achiever. Loves writing clean code and craft beautiful products. 👉 https://alpas.dev

Responses (12)