Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

Back Button Techniques
Multitenancy in Practice

Multitenancy in Practice

In this series, I'll show you how to build a single-database, multi-tenant application in Laravel. Together, we'll construct our application in such a way as to ensure that data from one tenant never leaks into the results for another tenant.

Intermediate
10 episodes
2h 25m
10
Latest Episode in This Series

Added 2 weeks ago

Interactive Charts

To wrap up this series, let's expand on the power of having all tenant data in one...

Watch
Multitenancy in Practice

Multitenancy in Practice

Version: Laravel 7

In this series, I'll show you how to build a single-database, multi-tenant application in Laravel. Together, we'll construct our application in such a way as to ensure that data from one tenant never leaks into the results for another tenant.

Begin
10
Latest Episode in This Series

Added 2 weeks ago

Interactive Charts

To wrap up this series, let's expand on the power of having all tenant data in one...
Watch

Your Teacher | Kevin McKee

https://laracasts.s3.amazonaws.com/avatars/kevinmckee.jpg's avatar

I am a TALL stack (Tailwind, Alpine, Laravel and Livewire) enthusiast. I have used Laravel to create a SaaS application, am the organizer of the LaravelSTL Meetup, and am passionate about helping people contribute to open source.

  1. Section 1 Initial Setup

    1. Free Episode Run Time 3:16

      In this series, you will learn about the simplicity and power of building a multi-tenant application with a single database. To illustrate this, we'll build an app using the TALL stack (Tailwind, Alpine, Livewire, and Laravel) with data segmented into tenants. Along the way, we'll additionally cover a handful of common multi-tenant features, such as image uploading and creating a super admin dashboard with impersonation and charts.

  2. Section 2 Tenants

    1. Free Episode Run Time 14:54 View Source

      To build multi-tenant functionality, we need to add the ability for a user to only see data that belong to his or her tenant in the database. To accomplish this, we'll set a Laravel global scope on every model.

    2. All data must be associated with a tenant in our database. We can use the new stub publishing feature that was introduced as part of Laravel 7 to allow for this. This will ensure that tenant ids are added to each model and set whenever data is created.

    3. Let's clean up this implementation a bit by writing some tests and then refactoring all the code within the Model stub to a BelongsToTenant trait.

  3. Section 3 Create the UI

    1. Tailwind UI is a premium product that can be used to quickly and easily create elegant web pages and components without hiring a designer. In this lesson, we'll use Alpine.js to implement the interactivity from Tailwind UI.

    2. It’s usually a good idea to extract reusable bits of code into Blade components. Let's set aside some time to extract a Livewire "text" input component and use whereStartsWith to get our wire:model attribute even when it includes a modifier.

  4. Section 4 Amazon S3 Uploads

    1. Many multi-tenant apps require image uploads, and may need to store those files in Amazon S3. Let’s create an Amazon S3 bucket from scratch and get it connected to our app. Then, we'll leverage the powerful and simple file uploading functionality that Livewire provides.

    2. If you have uploads that need to be restricted to only certain users in your application, in this lesson, I'll demonstrate a way to keep those uploads secure on S3 and stream their contents to the browser only after authorizing the user.

  5. Section 5 Super Admin Dashboard

    1. Providing support to the users of your multi-tenant application can be critical to the success of your product. Let's build a super admin dashboard that lists all the users in every tenant, and allows us to impersonate them as well.

    2. To wrap up this series, let's expand on the power of having all tenant data in one database by implementing some data visualization with the Laravel Charts package. We can build a useful chart for our super admin dashboard, and even deploy it to the tenant dashboard as well.