Create / Save header action for all resources at once

I would like to move the Create and Save action to the page header for all resources. I know I can use:
$this->getSaveFormAction();
$this->getCreateFormAction();
$this->getSaveFormAction();
$this->getCreateFormAction();
But I prefer the make the change once for all resources instead per resource (page).
3 Replies
Johan
JohanOP3w ago
<?php

namespace App\Filament\Concerns;

trait HeaderSaveOrCreateAction
{
public function bootedHeaderSaveOrCreateAction(): void
{
$this->cachedHeaderActions = array_filter([
...$this->cachedHeaderActions,
method_exists($this, 'getSaveFormAction')
? $this->getSaveFormAction()
->submit(null)
->action('save')
: null,
method_exists($this, 'getCreateFormAction')
? $this->getCreateFormAction()
->submit(null)
->action('create')
: null,
]);
}
}
<?php

namespace App\Filament\Concerns;

trait HeaderSaveOrCreateAction
{
public function bootedHeaderSaveOrCreateAction(): void
{
$this->cachedHeaderActions = array_filter([
...$this->cachedHeaderActions,
method_exists($this, 'getSaveFormAction')
? $this->getSaveFormAction()
->submit(null)
->action('save')
: null,
method_exists($this, 'getCreateFormAction')
? $this->getCreateFormAction()
->submit(null)
->action('create')
: null,
]);
}
}
Right now im calling this trait on each page, but feels not good.
awcodes
awcodes3w ago
Could probably ::macro() or ::configureUsing() the CreateRecord class in a service provider. Honestly, though, I’d go with the trait.
Johan
JohanOP3w ago
Mmm guess so.. still this is not ideal because it does not show file upload state etc. Would be great if we could configure the Save and Create button location within Filament

Did you find this page helpful?