90 lines
2.9 KiB
PHP
90 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\DepartmentResource\Pages;
|
|
use App\Filament\Resources\DepartmentResource\RelationManagers;
|
|
use App\Models\Department;
|
|
use App\Models\Faculty;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Toggle;
|
|
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 Illuminate\Support\Str;
|
|
|
|
class DepartmentResource extends Resource
|
|
{
|
|
protected static ?string $model = Department::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
|
|
|
protected static ?string $pluralLabel = 'Кафедры';
|
|
|
|
public static ?string $label = 'Кафедра';
|
|
|
|
|
|
protected static ?string $navigationParentItem = 'Факультеты';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
TextInput::make('title')->label('Название кафедры')->required()
|
|
->live(onBlur: true)
|
|
->afterStateUpdated(function (string $operation, $state, Forms\Set $set) {
|
|
$set('slug', Str::slug($state));
|
|
}),
|
|
TextInput::make('slug')->label('Slug')->unique(ignoreRecord: true)->readOnly()->required(),
|
|
Forms\Components\Select::make('faculty_id')
|
|
->options(Faculty::all()->pluck('title', 'id'))
|
|
->label('Факультет')
|
|
->required(),
|
|
Toggle::make('is_active')->default(true)->label('Активная кафедра')->inline(false),
|
|
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('title')->label('Название'),
|
|
Tables\Columns\TextColumn::make('faculty.title')->label('Факультет')->words(2)
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
RelationManagers\WorkersRelationManager::class,
|
|
RelationManagers\TeachersRelationManager::class,
|
|
RelationManagers\ProgramsRelationManager::class,
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListDepartments::route('/'),
|
|
'create' => Pages\CreateDepartment::route('/create'),
|
|
'edit' => Pages\EditDepartment::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|