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.
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.
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.
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.
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.
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.