Karthick K
Spatie Media Library on a custom page
<?php
namespace App\Filament\Admin\Resources\CertificateResource\Pages;
use App\Filament\Admin\Resources\CertificateResource;
use App\Models\Certificate;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\Page;
class UploadCertificate extends Page implements HasForms
{
use InteractsWithForms;
public Certificate $record;
public array $data = [];
protected static string $resource = CertificateResource::class;
protected static string $view = 'filament.admin.resources.certificate-resource.pages.upload-certificate';
public function mount(Certificate $record): void
{
$this->record = $record;
$record->load(['device','media']);
$this->form->fill([
'serial_number' => $record->serial_number,
'device_id' => $record->device->ecu_number,
'certificate' => $record->getMedia(),
]);
}
public function form(Form $form): Form
{
return $form->schema([
Section::make('Certificate Copy')
->schema([
SpatieMediaLibraryFileUpload::make('media')
->label('Upload Scanned Certificate'),
]),
])->statePath('data')
->model($this->record);
}
public function submit(): void
{
}
}
<?php
namespace App\Filament\Admin\Resources\CertificateResource\Pages;
use App\Filament\Admin\Resources\CertificateResource;
use App\Models\Certificate;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\Page;
class UploadCertificate extends Page implements HasForms
{
use InteractsWithForms;
public Certificate $record;
public array $data = [];
protected static string $resource = CertificateResource::class;
protected static string $view = 'filament.admin.resources.certificate-resource.pages.upload-certificate';
public function mount(Certificate $record): void
{
$this->record = $record;
$record->load(['device','media']);
$this->form->fill([
'serial_number' => $record->serial_number,
'device_id' => $record->device->ecu_number,
'certificate' => $record->getMedia(),
]);
}
public function form(Form $form): Form
{
return $form->schema([
Section::make('Certificate Copy')
->schema([
SpatieMediaLibraryFileUpload::make('media')
->label('Upload Scanned Certificate'),
]),
])->statePath('data')
->model($this->record);
}
public function submit(): void
{
}
}
11 replies