base commit
This commit is contained in:
120
app/Filament/Resources/Employees/EmployeeResource.php
Normal file
120
app/Filament/Resources/Employees/EmployeeResource.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Employees;
|
||||
|
||||
use App\Filament\Resources\Employees\Pages\CreateEmployee;
|
||||
use App\Filament\Resources\Employees\Pages\EditEmployee;
|
||||
use App\Filament\Resources\Employees\Pages\ListEmployees;
|
||||
use App\Filament\Resources\Employees\Pages\ViewEmployee;
|
||||
use App\Filament\Resources\Employees\RelationManagers\BonusesRelationManager;
|
||||
use App\Filament\Resources\Employees\RelationManagers\DisciplinaryReportsRelationManager;
|
||||
use App\Filament\Resources\Employees\RelationManagers\DocumentsRelationManager;
|
||||
use App\Filament\Resources\Employees\RelationManagers\ExplanationsRelationManager;
|
||||
use App\Filament\Resources\Employees\RelationManagers\GiftsRelationManager;
|
||||
use App\Filament\Resources\Employees\RelationManagers\SickLeavesRelationManager;
|
||||
use App\Filament\Resources\Employees\RelationManagers\UnpaidLeavesRelationManager;
|
||||
use App\Filament\Resources\Employees\RelationManagers\VacationsRelationManager;
|
||||
use App\Filament\Resources\Employees\Schemas\EmployeeForm;
|
||||
use App\Filament\Resources\Employees\Schemas\EmployeeInfolist;
|
||||
use App\Filament\Resources\Employees\Tables\EmployeesTable;
|
||||
use App\Models\Employee;
|
||||
use BackedEnum;
|
||||
use UnitEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class EmployeeResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Employee::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedUsers;
|
||||
|
||||
protected static string | UnitEnum | null $navigationGroup = 'Employees';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'full_name';
|
||||
|
||||
protected static bool $isGloballySearchable = true;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return EmployeeForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return EmployeeInfolist::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return EmployeesTable::configure($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return [
|
||||
'employee_number',
|
||||
'full_name',
|
||||
'phone',
|
||||
'department.name',
|
||||
'position.name',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function getGlobalSearchResultDetails(Model $record): array
|
||||
{
|
||||
/** @var Employee $record */
|
||||
return [
|
||||
'Employee #' => $record->employee_number,
|
||||
'Department' => $record->department?->name ?? '—',
|
||||
'Position' => $record->position?->name ?? '—',
|
||||
];
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
VacationsRelationManager::class,
|
||||
SickLeavesRelationManager::class,
|
||||
UnpaidLeavesRelationManager::class,
|
||||
DisciplinaryReportsRelationManager::class,
|
||||
ExplanationsRelationManager::class,
|
||||
BonusesRelationManager::class,
|
||||
GiftsRelationManager::class,
|
||||
DocumentsRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListEmployees::route('/'),
|
||||
'create' => CreateEmployee::route('/create'),
|
||||
'view' => ViewEmployee::route('/{record}'),
|
||||
'edit' => EditEmployee::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getRecordRouteBindingEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getRecordRouteBindingEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user