Stumped on file handling files with Forms + Spatie Media on Custom Page

I'm having issues handling a file upload on a custom page. I know I'm probably doing something stupid, but wondering if anyone will give me a sanity check.
<?php
class EditAccount extends Page implements HasForms
{
// ...
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->label('Company Name')
->required(),

SpatieMediaLibraryFileUpload::make('logo'),
])
->statePath('data');
}

public function save(): void
{
$data = $this->form->getState();
dd($data); // no `logo` in the data
$account = request()->user()->account;
$account->update($data);

}
}
<?php
class EditAccount extends Page implements HasForms
{
// ...
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->label('Company Name')
->required(),

SpatieMediaLibraryFileUpload::make('logo'),
])
->statePath('data');
}

public function save(): void
{
$data = $this->form->getState();
dd($data); // no `logo` in the data
$account = request()->user()->account;
$account->update($data);

}
}
This is my custom page for a single account edit. And below is the blade view for it:
<x-filament-panels::page>
<form wire:submit="save">
{{ $this->form }}
<button class="btn btn-primary" type="submit">Save</button>
</form>
</x-filament-panels::page>
<x-filament-panels::page>
<form wire:submit="save">
{{ $this->form }}
<button class="btn btn-primary" type="submit">Save</button>
</form>
</x-filament-panels::page>
On save, the $data = $this->form->getState(); contains the name input data, but no file uploads. Is it because of the data state path? I know I'm overlooking something simple but stuck at the moment
3 Replies
Luiz
Luiz3w ago
I'm in the same situation as you. Did you find any solution?
Wrax
Wrax3w ago
Did you give the form access to the model?
use App\Models\Post;
use Filament\Forms\Form;

public Post $post;

public function form(Form $form): Form
{
return $form
->schema([
// ...
])
->statePath('data')
->model($this->post);
}
use App\Models\Post;
use Filament\Forms\Form;

public Post $post;

public function form(Form $form): Form
{
return $form
->schema([
// ...
])
->statePath('data')
->model($this->post);
}
https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component#setting-a-form-model
n0nsensei
n0nsensei6d ago
$this->form->model($this->post)->saveRelationships();
$this->form->model($this->post)->saveRelationships();
this work for me on create page, but i have been stuck on how to load it in Cusom Edit Page, Edit:
SpatieMediaLibraryFileUpload::make('document')
->label('Upload Receipt Copy')
->collection('document')
->model($this->post)
->previewable(false)
->downloadable(true),
SpatieMediaLibraryFileUpload::make('document')
->label('Upload Receipt Copy')
->collection('document')
->model($this->post)
->previewable(false)
->downloadable(true),
this work for my custom edit page where, might also work for create haven't tried it.

Did you find this page helpful?