Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filamentβ€’4mo agoβ€’
10 replies
DigitalInfinity

Custom CreateAction in getHeaderActions redirects to Createpage of Resource

I try to make a CreateAction on a Resource to create a record of a different model.
This worked in Filamentphp 3.
I updated to Filamentphp 4 and now this is not working any more.
To not trap into some self-made problems like cache i created a new app from scratch with FilamentPHP 4.
Now i stripped everything down and have a Foo and a Bar Model with Resources and i addes a CreateAction to ViewBar.php:

<?php

namespace App\Filament\Resources\Bars\Pages;

use App\Filament\Resources\Bars\BarResource;
use Filament\Actions\EditAction;
use Filament\Resources\Pages\ViewRecord;

use Filament\Actions\CreateAction;
use Filament\Forms\Components\TextInput;

class ViewBar extends ViewRecord
{
    protected static string $resource = BarResource::class;

    protected function getHeaderActions(): array
    {
        return [
            EditAction::make(),
            CreateAction::make()
                ->schema([
                    TextInput::make('title')
                        ->required()
                        ->maxLength(255),
                    // ...
                ])
        ];
    }
}
<?php

namespace App\Filament\Resources\Bars\Pages;

use App\Filament\Resources\Bars\BarResource;
use Filament\Actions\EditAction;
use Filament\Resources\Pages\ViewRecord;

use Filament\Actions\CreateAction;
use Filament\Forms\Components\TextInput;

class ViewBar extends ViewRecord
{
    protected static string $resource = BarResource::class;

    protected function getHeaderActions(): array
    {
        return [
            EditAction::make(),
            CreateAction::make()
                ->schema([
                    TextInput::make('title')
                        ->required()
                        ->maxLength(255),
                    // ...
                ])
        ];
    }
}

So this is the exact example vom https://filamentphp.com/docs/4.x/actions/create#introduction
It should show a form with the field "title" when i click on it but the "new bar" button links to http://127.0.0.1:8001/admin/bars/create?record=1 and shows me the form to create a new Bar record

The code from my original app is this:
            Actions\CreateAction::make()
                ->label("Buchen")
                ->model(Booking::class)
                ->form(Booking::getForm())
        ];
            Actions\CreateAction::make()
                ->label("Buchen")
                ->model(Booking::class)
                ->form(Booking::getForm())
        ];

But it does the same -> redirect to the Create-Form of the Resource i put it in...

Am i doing something wrong?

Thank you.
Create action - Actions - Filament
Solution
ok i think we are getting closer.
maybe i'm a little disapointed because it was super intuitive in v3 and now just different πŸ˜‰

this works:
            Action::make('createBooking')
                ->label('Book')
                ->schema([
                    TextInput::make('title')
                        ->label("Titel")
                        ->required(),
                    Select::make('invoice_id')
                        ->label('Invoice')
                        ->relationship(name: 'invoice', titleAttribute: 'name')
                ])
                ->record(fn () => new Booking)
                ->action(function (array $data): void {
                    Booking::create($data);
                }),
            Action::make('createBooking')
                ->label('Book')
                ->schema([
                    TextInput::make('title')
                        ->label("Titel")
                        ->required(),
                    Select::make('invoice_id')
                        ->label('Invoice')
                        ->relationship(name: 'invoice', titleAttribute: 'name')
                ])
                ->record(fn () => new Booking)
                ->action(function (array $data): void {
                    Booking::create($data);
                }),


booking has a relationship to invoice.
but: when i remove the record() it tries to resolve this for the resource, i'm in (ToDo) which results in an error that there is no such relationship

i can live with this. thanks everybody for helping.

if i can figure out to use CreateAction for this again, i'll come back here πŸ™‚
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel β€’ Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

How to include a different resource CreateAction in resource CreateAction?
FilamentFFilament / β“β”Šhelp
2y ago
getHeaderActions with custom header view
FilamentFFilament / β“β”Šhelp
2y ago
How to add a CreateAction in the headerActions of resource A, to create a record in resource B?
FilamentFFilament / β“β”Šhelp
16mo ago