LAR_Maintenance/app/Providers/TenantServiceProvider.php
JonatanRek 571df9a0a4 Fixes
2024-07-30 18:13:21 +02:00

44 lines
1006 B
PHP

<?php
namespace App\Providers;
use App\Models\Tenant;
use App\Services\TenantManager;
use Illuminate\Support\ServiceProvider;
class TenantServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
$this->app->singleton(TenantManager::class, function () {
$tenant = null;
if (!app()->runningInConsole()) {
$tenant = Tenant::where('domain', explode(".", request()->getHost())[0])
->with(['users', 'settings'])
->first();
if (is_null($tenant)) {
abort(404, 'Tenant ' . explode(".", request()->getHost())[0] . ' not found (' . request()->getHost() . ')');
die();
}
}
return new TenantManager($tenant);
});
}
}