Simple package to support multi-tenancy in Laravel Jetstream using a trait, with some development niceties thrown in.
You can install the package via composer:
composer require chrisdicarlo/simple-jetstream-multitenancy
And then run the install command. This will prompt you to specify which model is the tenant and publish the config file:
php artisan sjm:install
You can create a migration to add the appropriate tenant columns to tables that should be tenant aware:
php artisan sjm:migration App\\Models\\Post
This will generate a migration file that looks like this:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::table('posts', function (Blueprint $table) {
$table->unsignedBigInteger('tenant_id')->nullable();
$table->foreign('tenant_id')->references('id')->on('users');
});
}
public function down()
{
Schema::table('posts', function (Blueprint $table) {
$table->dropForeign('tenant_id');
$table->dropColumn('tenant_id');
});
}
};
Lastly, add the ChrisDiCarlo\SimpleJetstreamMultitenancy\TenantAware trait to the applicable model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Chrisdicarlo\SimpleJetstreamMultitenancy\TenantAware;
class Post extends Model
{
...
use TenantAware;
...
}
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.