finished the upgrade to filament 4. completely revamped the frontend with codex, now it looks great!
This commit is contained in:
17
app/Filament/Resources/Users/Pages/CreateUser.php
Normal file
17
app/Filament/Resources/Users/Pages/CreateUser.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\UserResource\Pages;
|
||||
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateUser extends CreateRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
}
|
||||
24
app/Filament/Resources/Users/Pages/EditUser.php
Normal file
24
app/Filament/Resources/Users/Pages/EditUser.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\UserResource\Pages;
|
||||
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditUser extends EditRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
}
|
||||
52
app/Filament/Resources/Users/Pages/ListUsers.php
Normal file
52
app/Filament/Resources/Users/Pages/ListUsers.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\UserResource\Pages;
|
||||
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ListUsers extends ListRecords
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function shouldPersistTableFiltersInSession(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function shouldPersistTableSortInSession(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function shouldPersistTableSearchInSession(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function paginateTableQuery(Builder $query): Paginator
|
||||
{
|
||||
$paginator = parent::paginateTableQuery($query);
|
||||
return $paginator;
|
||||
}
|
||||
|
||||
public function updatedTablePage($page)
|
||||
{
|
||||
$this->dispatch('table-pagination-updated', ['tableId' => $this->id, 'page' => $page]);
|
||||
}
|
||||
|
||||
protected function getTableQueryStringIdentifier(): ?string
|
||||
{
|
||||
return 'users-table';
|
||||
}
|
||||
}
|
||||
126
app/Filament/Resources/Users/UserResource.php
Normal file
126
app/Filament/Resources/Users/UserResource.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\UserResource\Pages;
|
||||
use App\Filament\Resources\UserResource\RelationManagers;
|
||||
use App\Models\User;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Forms\Components\Select;
|
||||
|
||||
class UserResource extends Resource
|
||||
{
|
||||
protected static ?string $model = User::class;
|
||||
|
||||
protected static ?string $navigationGroup = 'User Management';
|
||||
protected static ?string $navigationLabel = 'User Roles';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Section::make('User Details')
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label(__('filament.resource.user.form.name'))
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('email')
|
||||
->label(__('filament.resource.user.form.email'))
|
||||
->email()
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('password')
|
||||
->label(__('filament.resource.user.form.password'))
|
||||
->password()
|
||||
->dehydrateStateUsing(fn (string $state): string => bcrypt($state))
|
||||
->dehydrated(fn (?string $state): bool => filled($state))
|
||||
->required(fn (string $operation): bool => $operation === 'create')
|
||||
->maxLength(255),
|
||||
Select::make('role_id')
|
||||
->relationship('role', 'name')
|
||||
->label(__('filament.resource.user.form.role'))
|
||||
->required(),
|
||||
])->columns(2),
|
||||
|
||||
Forms\Components\Section::make('Preferences')
|
||||
->schema([
|
||||
Forms\Components\Toggle::make('email_notifications_enabled')
|
||||
->label(__('Email Notifications'))
|
||||
->default(true),
|
||||
Select::make('theme_preference')
|
||||
->label(__('Theme'))
|
||||
->options([
|
||||
'light' => 'Light',
|
||||
'dark' => 'Dark',
|
||||
])
|
||||
->default('light'),
|
||||
Select::make('locale')
|
||||
->label(__('Language'))
|
||||
->options([
|
||||
'en' => 'English',
|
||||
'de' => 'Deutsch',
|
||||
])
|
||||
->default('en'),
|
||||
])->columns(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')->label(__('filament.resource.user.table.name'))->searchable()->sortable(),
|
||||
TextColumn::make('email')->label(__('filament.resource.user.table.email'))->searchable()->sortable(),
|
||||
TextColumn::make('role.name')->label(__('filament.resource.user.table.role'))->searchable()->sortable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListUsers::route('/'),
|
||||
'create' => Pages\CreateUser::route('/create'),
|
||||
'edit' => Pages\EditUser::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return __('filament.navigation.groups.user_management');
|
||||
}
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('filament.navigation.user_roles');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user