Seebad 0.3 stays in this release. With a single landlord every host still reaches the default website. Co-authored-by: Cursor <cursoragent@cursor.com>
92 lines
3.1 KiB
PHP
92 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Operator;
|
|
|
|
use App\Filament\Operator\Tenants\Pages\CreateTenant;
|
|
use App\Filament\Operator\Tenants\Pages\EditTenant;
|
|
use App\Filament\Operator\Tenants\Pages\ListTenants;
|
|
use App\Models\Tenant;
|
|
use App\Models\TenantAccessLog;
|
|
use BackedEnum;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Toggle;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Columns\ToggleColumn;
|
|
use Filament\Tables\Table;
|
|
|
|
class TenantResource extends Resource
|
|
{
|
|
protected static ?string $model = Tenant::class;
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedBuildingOffice;
|
|
|
|
protected static ?string $modelLabel = 'Mandant';
|
|
|
|
protected static ?string $pluralModelLabel = 'Mandanten';
|
|
|
|
protected static ?string $navigationLabel = 'Mandanten';
|
|
|
|
protected static ?int $navigationSort = 1;
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
TextInput::make('name')
|
|
->label('Name')
|
|
->required()
|
|
->maxLength(255),
|
|
TextInput::make('slug')
|
|
->label('Kurzname')
|
|
->required()
|
|
->alphaDash()
|
|
->unique(ignoreRecord: true)
|
|
->maxLength(255),
|
|
Toggle::make('is_active')
|
|
->label('Aktiv')
|
|
->helperText('Ein gesperrter Mandant ist von außen nicht mehr erreichbar. Der Betreiber kommt weiter hinein.')
|
|
->default(true),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('name')->label('Name')->searchable(),
|
|
TextColumn::make('slug')->label('Kurzname'),
|
|
ToggleColumn::make('is_active')->label('Aktiv'),
|
|
])
|
|
->recordActions([
|
|
EditAction::make(),
|
|
Action::make('openAdmin')
|
|
->label('Im Admin öffnen')
|
|
->icon(Heroicon::OutlinedArrowTopRightOnSquare)
|
|
->action(function (Tenant $record) {
|
|
TenantAccessLog::query()->create([
|
|
'tenant_id' => $record->id,
|
|
'user_id' => auth()->id(),
|
|
]);
|
|
|
|
$domain = $record->sites()->withoutGlobalScope('tenant')->whereNotNull('domain')->value('domain');
|
|
|
|
return redirect(is_string($domain) && $domain !== '' ? 'https://'.$domain.'/admin' : url('/admin'));
|
|
}),
|
|
]);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListTenants::route('/'),
|
|
'create' => CreateTenant::route('/create'),
|
|
'edit' => EditTenant::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|