iamkevinmckee/single-database-tenancy

A simple package to create multi-tenant applications with a single database.

0.1 2020-05-29 03:39 UTC

This package is auto-updated.

Last update: 2024-08-29 05:32:45 UTC


README

Latest Version on Packagist Total Downloads

This is a package to help you create a multi-tenant application in Laravel with a single database. It is best used at the beginning of a new project.

Installation

You can install the package via composer:

composer require iamkevinmckee/single-database-tenancy

Usage

After installing the package, you will need to create a Tenant model.

php artisan make:model Tenant -m

You will also need to add a tenant_id to your users table.

php artisan make:migration add_tenant_id_to_users_table

Next you will want to publish the stubs. This will ensure every subsequent model has a migration with a tenant_id. For this to work, you must create your models with the -m flag so a migration is also created with the model.

php artisan single-db-tenancy:stubs

At this point, you just need to make sure each User has a tenant_id assigned to them when they register and all Eloquent operations will be scoped to the tenant.

When inserting data into the database via Eloquent, the tenant_id will automatically be set to the tenant_id of the user submitting the data.

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please open an issue before submitting a PR to ensure the feature will be accepted.

Security

If you discover any security related issues, please email kevin@kevinmckee.me instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.