You've already forked Atomcms-edit
Initial commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Hotel\BadgeUploads;
|
||||
|
||||
use App\Filament\Resources\Hotel\BadgeUploads\Pages\ManageBadgeUploads;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
|
||||
class BadgeUploadResource extends Resource
|
||||
{
|
||||
#[\Override]
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Hotel';
|
||||
|
||||
#[\Override]
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-gif';
|
||||
|
||||
#[\Override]
|
||||
protected static ?string $label = 'Badge Upload';
|
||||
|
||||
#[\Override]
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
FileUpload::make('badge_file')
|
||||
->label('Upload Badge')
|
||||
->disk('local')
|
||||
->directory(setting('badge_path_filesystem'))
|
||||
->required()
|
||||
->getUploadedFileNameForStorageUsing(
|
||||
fn (TemporaryUploadedFile $file): string => strtolower(str_replace([' ', '-', 'æ', 'ø', 'å'], ['_', '_', 'ae', 'oe', 'aa'], $file->getClientOriginalName())),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('filename')
|
||||
->label('File Name')
|
||||
->sortable(),
|
||||
TextColumn::make('path')
|
||||
->label('File Path'),
|
||||
])
|
||||
->filters([]);
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ManageBadgeUploads::route('/'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getFiles(): array
|
||||
{
|
||||
$badgePath = env('BadgePath', 'badges');
|
||||
$files = Storage::disk('local')->files($badgePath);
|
||||
|
||||
return collect($files)->map(fn ($file) => [
|
||||
'filename' => basename($file),
|
||||
'path' => $file,
|
||||
])->toArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user