56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Filament\Resources;
|
||
|
|
|
||
|
|
use App\Filament\Resources\UserResource\Pages;
|
||
|
|
use App\Models\User;
|
||
|
|
use Filament\Forms\Components\Select;
|
||
|
|
use Filament\Forms\Components\TextInput;
|
||
|
|
use Filament\Forms\Form;
|
||
|
|
use Filament\Resources\Resource;
|
||
|
|
use Filament\Tables\Actions\DeleteAction;
|
||
|
|
use Filament\Tables\Actions\EditAction;
|
||
|
|
use Filament\Tables\Columns\TextColumn;
|
||
|
|
use Filament\Tables\Table;
|
||
|
|
|
||
|
|
class UserResource extends Resource
|
||
|
|
{
|
||
|
|
protected static ?string $model = User::class;
|
||
|
|
protected static ?string $navigationIcon = 'heroicon-o-users';
|
||
|
|
protected static ?string $label = 'Benutzer';
|
||
|
|
protected static ?string $pluralLabel = 'Benutzer';
|
||
|
|
|
||
|
|
public static function form(Form $form): Form
|
||
|
|
{
|
||
|
|
return $form->schema([
|
||
|
|
TextInput::make('name')->required()->maxLength(255),
|
||
|
|
TextInput::make('email')->email()->required()->maxLength(255),
|
||
|
|
TextInput::make('password')->password()->dehydrateStateUsing(fn ($state) => bcrypt($state))
|
||
|
|
->required(fn (string $context) => $context === 'create'),
|
||
|
|
Select::make('role')
|
||
|
|
->options(['admin' => 'Admin', 'staff' => 'Mitarbeiter'])
|
||
|
|
->required(),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function table(Table $table): Table
|
||
|
|
{
|
||
|
|
return $table->columns([
|
||
|
|
TextColumn::make('name')->searchable(),
|
||
|
|
TextColumn::make('email')->searchable(),
|
||
|
|
TextColumn::make('role')->badge()
|
||
|
|
->color(fn (string $state) => $state === 'admin' ? 'danger' : 'gray'),
|
||
|
|
TextColumn::make('created_at')->dateTime()->sortable(),
|
||
|
|
])->actions([EditAction::make(), DeleteAction::make()]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getPages(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'index' => Pages\ListUsers::route('/'),
|
||
|
|
'create' => Pages\CreateUser::route('/create'),
|
||
|
|
'edit' => Pages\EditUser::route('/{record}/edit'),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|