106 lines
3.7 KiB
PHP
106 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Resources\Employees\RelationManagers;
|
|
|
|
use App\Enums\DocumentType;
|
|
use App\Filament\Support\HrForm;
|
|
use App\Models\EmployeeDocument;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\CreateAction;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Actions\ForceDeleteBulkAction;
|
|
use Filament\Actions\RestoreBulkAction;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Filters\TrashedFilter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class DocumentsRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'documents';
|
|
|
|
protected static ?string $title = 'Employee Documents';
|
|
|
|
public function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
Select::make('document_type')
|
|
->options(DocumentType::class)
|
|
->required()
|
|
->native(false),
|
|
TextInput::make('title')
|
|
->required()
|
|
->maxLength(255),
|
|
HrForm::fileUpload('file_path')
|
|
->label('Document')
|
|
->required()
|
|
->acceptedFileTypes(['application/pdf', 'image/*', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'])
|
|
->maxSize(15360),
|
|
]);
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->recordTitleAttribute('title')
|
|
->columns([
|
|
TextColumn::make('document_type')
|
|
->label('Type')
|
|
->badge()
|
|
->color(fn (DocumentType $state): string => $state->color())
|
|
->formatStateUsing(fn (DocumentType $state): string => $state->label())
|
|
->sortable(),
|
|
TextColumn::make('title')
|
|
->searchable()
|
|
->sortable(),
|
|
TextColumn::make('uploaded_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->filters([
|
|
SelectFilter::make('document_type')
|
|
->label('Type')
|
|
->options(DocumentType::class),
|
|
TrashedFilter::make(),
|
|
])
|
|
->headerActions([
|
|
CreateAction::make(),
|
|
])
|
|
->recordActions([
|
|
Action::make('download')
|
|
->label('Download')
|
|
->icon('heroicon-o-arrow-down-tray')
|
|
->visible(fn (EmployeeDocument $record): bool => filled($record->file_path))
|
|
->action(function (EmployeeDocument $record) {
|
|
$disk = Storage::disk(config('hr.file_uploads.disk'));
|
|
|
|
return response()->download(
|
|
$disk->path($record->file_path),
|
|
basename($record->file_path),
|
|
);
|
|
}),
|
|
EditAction::make(),
|
|
DeleteAction::make(),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make(),
|
|
ForceDeleteBulkAction::make(),
|
|
RestoreBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
}
|