base commit
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\EmployeeDocuments;
|
||||
|
||||
use App\Filament\Resources\EmployeeDocuments\Pages\CreateEmployeeDocument;
|
||||
use App\Filament\Resources\EmployeeDocuments\Pages\EditEmployeeDocument;
|
||||
use App\Filament\Resources\EmployeeDocuments\Pages\ListEmployeeDocuments;
|
||||
use App\Filament\Resources\EmployeeDocuments\Pages\ViewEmployeeDocument;
|
||||
use App\Filament\Resources\EmployeeDocuments\Schemas\EmployeeDocumentForm;
|
||||
use App\Filament\Resources\EmployeeDocuments\Schemas\EmployeeDocumentInfolist;
|
||||
use App\Filament\Resources\EmployeeDocuments\Tables\EmployeeDocumentsTable;
|
||||
use App\Models\EmployeeDocument;
|
||||
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\SoftDeletingScope;
|
||||
|
||||
class EmployeeDocumentResource extends Resource
|
||||
{
|
||||
protected static ?string $model = EmployeeDocument::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedDocument;
|
||||
|
||||
protected static string | UnitEnum | null $navigationGroup = 'Records';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'title';
|
||||
|
||||
protected static bool $isGloballySearchable = false;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return EmployeeDocumentForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return EmployeeDocumentInfolist::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return EmployeeDocumentsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListEmployeeDocuments::route('/'),
|
||||
'create' => CreateEmployeeDocument::route('/create'),
|
||||
'view' => ViewEmployeeDocument::route('/{record}'),
|
||||
'edit' => EditEmployeeDocument::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getRecordRouteBindingEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getRecordRouteBindingEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\EmployeeDocuments\Pages;
|
||||
|
||||
use App\Filament\Resources\EmployeeDocuments\EmployeeDocumentResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateEmployeeDocument extends CreateRecord
|
||||
{
|
||||
protected static string $resource = EmployeeDocumentResource::class;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\EmployeeDocuments\Pages;
|
||||
|
||||
use App\Filament\Resources\EmployeeDocuments\EmployeeDocumentResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\ForceDeleteAction;
|
||||
use Filament\Actions\RestoreAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditEmployeeDocument extends EditRecord
|
||||
{
|
||||
protected static string $resource = EmployeeDocumentResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
ViewAction::make(),
|
||||
DeleteAction::make(),
|
||||
ForceDeleteAction::make(),
|
||||
RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\EmployeeDocuments\Pages;
|
||||
|
||||
use App\Filament\Resources\EmployeeDocuments\EmployeeDocumentResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListEmployeeDocuments extends ListRecords
|
||||
{
|
||||
protected static string $resource = EmployeeDocumentResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\EmployeeDocuments\Pages;
|
||||
|
||||
use App\Filament\Resources\EmployeeDocuments\EmployeeDocumentResource;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewEmployeeDocument extends ViewRecord
|
||||
{
|
||||
protected static string $resource = EmployeeDocumentResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\EmployeeDocuments\Schemas;
|
||||
|
||||
use App\Enums\DocumentType;
|
||||
use App\Filament\Support\HrForm;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class EmployeeDocumentForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
HrForm::employeeSelect(),
|
||||
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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\EmployeeDocuments\Schemas;
|
||||
|
||||
use App\Models\EmployeeDocument;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class EmployeeDocumentInfolist
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextEntry::make('employee.id')
|
||||
->label('Employee'),
|
||||
TextEntry::make('document_type')
|
||||
->badge(),
|
||||
TextEntry::make('title'),
|
||||
TextEntry::make('file_path'),
|
||||
TextEntry::make('uploaded_at')
|
||||
->dateTime(),
|
||||
TextEntry::make('created_at')
|
||||
->dateTime()
|
||||
->placeholder('-'),
|
||||
TextEntry::make('updated_at')
|
||||
->dateTime()
|
||||
->placeholder('-'),
|
||||
TextEntry::make('deleted_at')
|
||||
->dateTime()
|
||||
->visible(fn (EmployeeDocument $record): bool => $record->trashed()),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\EmployeeDocuments\Tables;
|
||||
|
||||
use App\Enums\DocumentType;
|
||||
use App\Models\EmployeeDocument;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ForceDeleteBulkAction;
|
||||
use Filament\Actions\RestoreBulkAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
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 EmployeeDocumentsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('employee.full_name')
|
||||
->label('Employee')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('document_type')
|
||||
->label('Type')
|
||||
->badge()
|
||||
->color(fn (DocumentType $state): string => $state->color())
|
||||
->formatStateUsing(fn (DocumentType $state): string => $state->label())
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('title')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('uploaded_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('deleted_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('document_type')
|
||||
->label('Type')
|
||||
->options(DocumentType::class),
|
||||
TrashedFilter::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),
|
||||
);
|
||||
}),
|
||||
ViewAction::make(),
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
ForceDeleteBulkAction::make(),
|
||||
RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user