henryavila/laravel-nova-multitenancy
Composer 安装命令:
composer require henryavila/laravel-nova-multitenancy
包简介
Integrate the multi tenancy single database in Laravel Nova.
README 文档
README
Integrate the multitenancy single database in Laravel Nova.
This package is based on https://spatie.be/docs/laravel-multitenancy. So logic and config of spatie/laravel-multitenancy still aplies
Installation
You can install the package via composer:
composer require henryavila/laravel-nova-multitenancy
You can publish the config, view, migrations and translation with:
php artisan vendor:publish --provider="HenryAvila\LaravelNovaMultitenancy\LaravelNovaMultitenancyServiceProvider"
The views file will be published, personalize it at your will.
Don't forget to run npm run build
You can run the migration with (To create the Tenant table)
php artisan migrate
Edit the app\Http\Kernel.php file adding an entry in web group and creating the tenant group
protected $middlewareGroups = [ // ... 'web' => [ // ... \HenryAvila\LaravelNovaMultitenancy\Http\Middleware\SetTenantMiddleware::class, ], // ... 'tenant' => [ \HenryAvila\LaravelNovaMultitenancy\Http\Middleware\NeedsTenant::class, \HenryAvila\LaravelNovaMultitenancy\Http\Middleware\EnsureValidTenantSession::class, ] ];
If you activated (User Impersonation)[https://nova.laravel.com/docs/4.0/customization/impersonation.html] on Laravel Nova, you must set up this event Listeners.
Edit the file App\Providers\EventServiceProvider and add:
protected $listen = [ \Laravel\Nova\Events\StartedImpersonating::class => [ \HenryAvila\LaravelNovaMultitenancy\Listeners\ClearTenantSessionListener::class, ], \Laravel\Nova\Events\StoppedImpersonating::class => [ \HenryAvila\LaravelNovaMultitenancy\Listeners\ClearTenantSessionListener::class, ], ];
Make your User model extends \HenryAvila\LaravelNovaMultitenancy\Models\User
If you want to customize the Tenant model, change it in config file
Add the trait \HenryAvila\LaravelNovaMultitenancy\Traits\ModelWithTenant to all models that are tenant aware
Add to your database file a tenant_connection entry with the tenant db connection. See:
return [ // database.php 'tenant_connection' => env('DB_TENANT_CONNECTION', 'tenant'),
This is the relation between the connections and the database
| Name | Database |
|---|---|
| default | Landlord database |
| tenant_connection | Tenant database |
PS.: Don't forget to create this connections in database.connections config file.
Usage
To protect a specific route, just add the 'tenant' middleware to route
// in a routes file Route::middleware('tenant')->group(function() { // routes });
If you receive an error: Route [login] not defined..
Remember to change the route from login to nova.login in your App\Http\Middleware\Authenticate file
protected function redirectTo($request) { return $request->expectsJson() ? null : route('nova.login'); }
Another option to don't define the tenant to an route is set the following default data to route declaration
Route::get('/', [Controller::class, 'index']) ->defaults(\HenryAvila\LaravelNovaMultitenancy\LaravelNovaMultitenancy::SKIP_ROUTE, true);
If the Tenant has domains relationship, allow to define the current tenant based on current domain.
The domains relation model, must contain an fqdn attribute with the fqdn domain
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
henryavila/laravel-nova-multitenancy 适用场景与选型建议
henryavila/laravel-nova-multitenancy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 150 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 08 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「henryavila」 「laravel-nova-multitenancy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 henryavila/laravel-nova-multitenancy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 henryavila/laravel-nova-multitenancy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 henryavila/laravel-nova-multitenancy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Track e-mail delivery with Mailgun Hooks. All data are stored in the database on Email model
Track e-mail delivery with Mailgun Hooks and display the report on Laravel Nova Dashboard
Alfabank REST API integration
This package provides an abstraction to efficiently manage multiple database application commands, like: migrate
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
统计信息
- 总下载量: 150
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2023-08-18