Untitled

mail@pastecode.io avatar
unknown
php
a year ago
1.2 kB
4
Indexable
Never
<?php

namespace App\Filament\Pages;

use Filament\Forms\Components\FileUpload;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Pages\Page;

class Settings extends Page implements HasForms
{
    use InteractsWithForms;

    protected static ?string $navigationIcon = 'heroicon-o-document-text';
    protected static string $view = 'filament.pages.settings';

    public $logo;

    public function mount(): void
    {
        $this->form->fill([
            'logo' => 'logo/logo.png',
        ]);
    }

    protected function getFormSchema(): array
    {
        return [
            FileUpload::make('logo')
                ->image()
                // when i submit the form without an image uploaded, I do not get a validation error
                ->required()
                ->rules(['mimes:png']),
        ];
    }

    public function submit(): void
    {
        // When this is commented out, the image at the path storage/logo/logo.png is not updated
        // collect($this->logo)->first()->storeAs('logo', 'logo.png', 'public');

        $this->notify('success', 'Saved successfully!');
    }
}