larawire-garage/simple-multitenancy

Support user multitenancy for laravel application

v1.0.0 2024-08-31 23:38 UTC

This package is auto-updated.

Last update: 2025-04-29 01:44:04 UTC


README

Support Multitenancy for laravel application

Installation

composer require larawire-garage/simple-multitenancy

publish configurations

php artisan vendor:publish --tag=simple-mutitenancy-configs

Usage

call userBy() at the end of the Schema create callback function in the migration file

Schema::create('users', function (Blueprint $table) {
    // other columns
    
    $table->userBy();
});

The userBy(bool $hasSoftDeletes = true) function will add following columns to the table

  • created_by
  • updated_by
  • deleted_by [only $hasSoftDeletes == true]

Inside the Model
use HasUserBy trait in the model which needed multitenancy

// app/Models/User.php
class User extends Authenticatable {
    use HasUserBy;
}

// app/Models/Post.php
class Post extends Model {
    use HasUserBy;
}

Retrieve User

$post->createdBy(); // return App\Models\User|null
$post->updatedBy(); // return App\Models\User|null
$post->deletedBy(); // return App\Models\User|null

!!! 🎉🎉🎉 Enjoy 🎉🎉🎉 !!!