Overview | laravel-multitenancy | Spatie

 SPATIE

  Laravel Multitenancy
=======================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-multitenancy](https://spatie.be/docs/laravel-multitenancy/v1)  Using-tasks-to-prepare-the-environment  Overview

 Version   v4   v3   v2   v1

 Other versions for crawler [v4](https://spatie.be/docs/laravel-multitenancy/v4) [v3](https://spatie.be/docs/laravel-multitenancy/v3) [v2](https://spatie.be/docs/laravel-multitenancy/v2) [v1](https://spatie.be/docs/laravel-multitenancy/v1)

  Overview
- [ Introduction ](https://spatie.be/docs/laravel-multitenancy/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-multitenancy/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-multitenancy/v1/requirements)
- [ Questions and issues ](https://spatie.be/docs/laravel-multitenancy/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-multitenancy/v1/changelog)
- [ ](https://spatie.be/docs/laravel-multitenancy/v1/installation-setup)

Installation
------------

- [ Base installation ](https://spatie.be/docs/laravel-multitenancy/v1/installation/base-installation)
- [ Using a single database ](https://spatie.be/docs/laravel-multitenancy/v1/installation/using-a-single-database)
- [ Using multiple databases ](https://spatie.be/docs/laravel-multitenancy/v1/installation/using-multiple-databases)
- [ Determining the current tenant ](https://spatie.be/docs/laravel-multitenancy/v1/installation/determining-current-tenant)

Basic usage
-----------

- [ Automatically determining the current tenant ](https://spatie.be/docs/laravel-multitenancy/v1/basic-usage/automatically-determining-the-current-tenant)
- [ Working with the current tenant ](https://spatie.be/docs/laravel-multitenancy/v1/basic-usage/working-with-the-current-tenant)
- [ Making queues tenant aware ](https://spatie.be/docs/laravel-multitenancy/v1/basic-usage/making-queues-tenant-aware)

Advanced usage
--------------

- [ Ensuring a current tenant has been set ](https://spatie.be/docs/laravel-multitenancy/v1/advanced-usage/ensuring-a-current-tenant-has-been-set)
- [ Looping over a collection of tenants ](https://spatie.be/docs/laravel-multitenancy/v1/advanced-usage/looping-over-a-collection-of-tenants)
- [ Making Artisan command tenant aware ](https://spatie.be/docs/laravel-multitenancy/v1/advanced-usage/making-artisan-commands-tenant-aware)
- [ Using a custom tenant model ](https://spatie.be/docs/laravel-multitenancy/v1/advanced-usage/using-a-custom-tenant-model)
- [ Listening for events ](https://spatie.be/docs/laravel-multitenancy/v1/advanced-usage/listening-for-events)
- [ Executing code for tenants and landlords ](https://spatie.be/docs/laravel-multitenancy/v1/advanced-usage/executing-code-for-tenants-and-landlords)

Using tasks to prepare the environment
--------------------------------------

- [ Overview ](https://spatie.be/docs/laravel-multitenancy/v1/using-tasks-to-prepare-the-environment/overview)
- [ Creating your own task ](https://spatie.be/docs/laravel-multitenancy/v1/using-tasks-to-prepare-the-environment/creating-your-own-task)
- [ Switching databases ](https://spatie.be/docs/laravel-multitenancy/v1/using-tasks-to-prepare-the-environment/switching-databases)
- [ Prefixing cache ](https://spatie.be/docs/laravel-multitenancy/v1/using-tasks-to-prepare-the-environment/prefixing-cache)

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/laravel-multitenancy                                                                                                                                                                                                                                    `

Overview
========

When making a tenant the current one, the tasks inside the `switch_tenant_tasks` key of the `multitenancy` config file will be executed. Inside these tasks you can perform logic to configure the environment for the tenant that is being made the current one.

The philosophy of this package is that it should only provide the bare essentials to enable multitenancy. That's why it only provides two tasks out of the box. These tasks serve as example implementations.

You can easily [create your own tasks](/docs/laravel-multitenancy/v1/using-tasks-to-prepare-the-environment/creating-your-own-task/) that fit your particular project.

The package ships with these tasks:

- [switch the tenant database](/docs/laravel-multitenancy/v1/using-tasks-to-prepare-the-environment/switching-databases) (required when using multiple tenant databases)
- [prefixing the cache](/docs/laravel-multitenancy/v1/using-tasks-to-prepare-the-environment/prefixing-cache)

These tasks are optional. When you need one, just add it to the `switch_tenant_tasks` key of the `multitenancy` config file.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
