Files
telekeci/app/Filament/Resources/OutgoingLetterResource.php

88 lines
2.5 KiB
PHP

<?php
namespace App\Filament\Resources;
use App\Filament\Resources\OutgoingLetterResource\Pages;
use App\Modules\OutgoingLetter\Models\OutgoingLetter;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Forms\Components\FileUpload;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;
class OutgoingLetterResource extends Resource
{
protected static ?string $model = OutgoingLetter::class;
protected static ?string $navigationIcon = 'heroicon-o-document-arrow-up';
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('number')
->integer()
->required()
->default(fn () => getLatestNumber() + 1),
TextInput::make('name')
->required(),
FileUpload::make('main_file'),
]);
}
public static function table(Table $table): Table
{
return $table
->defaultSort('number', 'desc')
->columns([
TextColumn::make('number')
->searchable()
->sortable(query: fn (Builder $query, string $direction) => $query->orderByRaw("CAST(number AS UNSIGNED) $direction")),
TextColumn::make('name')
->searchable()
->sortable(),
TextColumn::make('created_at')
->dateTime()
->sortable()
->sinceTooltip()
->formatStateUsing(fn (?Carbon $state) => $state?->format('H:i, d.m.Y')),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListOutgoingLetters::route('/'),
'create' => Pages\CreateOutgoingLetter::route('/create'),
'edit' => Pages\EditOutgoingLetter::route('/{record}/edit'),
];
}
}