Last active
August 30, 2023 06:31
-
-
Save bilogic/439e7634124a6aa9626c3e24236a9796 to your computer and use it in GitHub Desktop.
filament custom page with SpatieMediaLibraryFileUpload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Filament\Pages; | |
use App\Models\Staff; | |
use Filament\Actions\Action; | |
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\Pages\Page; | |
class Profile extends Page implements HasForms | |
{ | |
use InteractsWithForms; | |
public ?array $data = []; | |
protected static ?string $navigationIcon = 'heroicon-o-document-text'; | |
protected static string $view = 'filament.pages.profile'; | |
protected ?string $subheading = 'Custom Page Subheading'; | |
protected static ?string $navigationGroup = 'Business'; | |
protected $staff; | |
public function mount(): void | |
{ | |
$this->staff = Staff::all()->first(); | |
$this->form->fill($this->staff->toArray()); | |
} | |
public function form(Form $form): Form | |
{ | |
return $form | |
->schema([ | |
TextInput::make('name') | |
->required(), | |
SpatieMediaLibraryFileUpload::make('image') | |
->label("Photo") | |
->collection('staff-image'), | |
]) | |
->model($this->staff) | |
->statePath('data'); | |
} | |
public function save() | |
{ | |
$this->validate(); | |
// SAVE THE SETTINGS HERE | |
} | |
protected function getHeaderActions(): array | |
{ | |
return [ | |
Action::make('edit'), | |
]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Filament\Pages; | |
use Filament\Actions\Action; | |
use Filament\Forms\Components\FileUpload; | |
use Filament\Forms\Concerns\InteractsWithForms; | |
use Filament\Forms\Contracts\HasForms; | |
use Filament\Forms\Form; | |
use Filament\Pages\Page; | |
class Test extends Page implements HasForms | |
{ | |
use InteractsWithForms; | |
public ?array $data = []; | |
protected static string $view = 'filament.pages.profile'; | |
public function mount(): void | |
{ | |
$this->form->fill([ | |
// 'logo' => 'public/support/img/clip.png', // doesn't work | |
'logo' => 'support/img/clip.png', // doesn't work too | |
]); | |
} | |
public function form(Form $form): Form | |
{ | |
return $form | |
->schema([ | |
FileUpload::make('logo') | |
->image() | |
->reorderable() | |
->openable() | |
->downloadable() | |
->imageEditor(), | |
]) | |
->statePath('data'); | |
} | |
public function save() | |
{ | |
$this->validate(); | |
// SAVE THE SETTINGS HERE | |
} | |
protected function getHeaderActions(): array | |
{ | |
return [ | |
Action::make('edit'), | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment