Editing image in custom page
Hi All,
I am using stancl tenancy with filament. I have this custom page to change the branding of the tenant. Code Below:
I am using stancl tenancy with filament. I have this custom page to change the branding of the tenant. Code Below:
class Branding extends Page implements HasForms
{
use InteractsWithForms;
use WithFileUploads;
protected static ?string $navigationIcon = 'heroicon-o-paint-brush';
protected static ?string $navigationGroup = 'Settings';
protected static string $view = 'filament.tenant.pages.branding';
public ?array $data = [];
public function mount(): void
{
// TODO: fill existing images or allow users to clear
$this->form->fill([
'name' => tenant('name'),
'primary_color' => tenant('primary_color'),
'logo' => tenant_asset(tenant('logo')),
'favicon' => tenant_asset('favicon'),
]);
}
public function form(Form $form): Form
{
return $form->schema(BrandingForm::schema())->statePath('data');
}
public function submit()
{
$this->validate();
if (!empty($this->data['logo'])) {
reset($this->data['logo']);
$logo = current($this->data['logo']);
$logoUrl = $logo->store('logos', 'public');
} else {
$logoUrl = tenant('logo');
}
if (!empty($this->data['favicon'])) {
reset($this->data['favicon']);
$favicon = current($this->data['favicon']);
$faviconUrl = $favicon->store('favicons', 'public');
} else {
$faviconUrl = tenant('favicon');
}
tenant()->update([
'name' => $this->data['name'],
'primary_color' => $this->data['primary_color'],
'logo' => $logoUrl,
'favicon' => $faviconUrl,
]);
Notification::make()
->title('Branding updated')
->success()
->send();
$this->dispatch('reload');
}
}class Branding extends Page implements HasForms
{
use InteractsWithForms;
use WithFileUploads;
protected static ?string $navigationIcon = 'heroicon-o-paint-brush';
protected static ?string $navigationGroup = 'Settings';
protected static string $view = 'filament.tenant.pages.branding';
public ?array $data = [];
public function mount(): void
{
// TODO: fill existing images or allow users to clear
$this->form->fill([
'name' => tenant('name'),
'primary_color' => tenant('primary_color'),
'logo' => tenant_asset(tenant('logo')),
'favicon' => tenant_asset('favicon'),
]);
}
public function form(Form $form): Form
{
return $form->schema(BrandingForm::schema())->statePath('data');
}
public function submit()
{
$this->validate();
if (!empty($this->data['logo'])) {
reset($this->data['logo']);
$logo = current($this->data['logo']);
$logoUrl = $logo->store('logos', 'public');
} else {
$logoUrl = tenant('logo');
}
if (!empty($this->data['favicon'])) {
reset($this->data['favicon']);
$favicon = current($this->data['favicon']);
$faviconUrl = $favicon->store('favicons', 'public');
} else {
$faviconUrl = tenant('favicon');
}
tenant()->update([
'name' => $this->data['name'],
'primary_color' => $this->data['primary_color'],
'logo' => $logoUrl,
'favicon' => $faviconUrl,
]);
Notification::make()
->title('Branding updated')
->success()
->send();
$this->dispatch('reload');
}
}