FilamentF
Filamentβ€’3y ago
DivDax

SpatieMediaLibraryFileUpload show uploaded images

Hey! πŸ‘‹

I want to use the Form Builder inside a Widget to upload images. The upload is working and my media files are stored on disk and in the media table. When i reload the page the uploaded images are gone. Storage path is linked and i have no console errors. The Field inside a Resource on the edit page it works.

Any idea what i'm doing wrong?

<?php

namespace App\Filament\Widgets;

use App\Models\Page;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Widgets\Widget;
use Filament\Forms;

class LinkpageImages extends Widget implements HasForms
{
    use InteractsWithForms;

    protected static string $view = 'filament.widgets.linkpage-images';

    protected static ?string $pollingInterval = null;

    public $pages;

    public $images;

    public function mount(): void
    {
        $this->pages = Page::get();
    }

    protected function getFormSchema()
    {
        $fields = [];

        foreach ($this->pages as $page) {
            $fields[] = Forms\Components\SpatieMediaLibraryFileUpload::make('images')
                ->collection('background')
                ->model($page)
                ->image()
                ->maxSize(1024*3)
                ->required();
        }

        return [
            Forms\Components\Grid::make(2)
                ->schema($fields)
        ];
    }

    public function submit(): void
    {
        dd($this->form->getState());
    }
}
Was this page helpful?