Relation Manager create record using Resource page instead of modal
The default behaviour when hitting the Create button on the Relation Manager is for the new record form to be displayed in a modal.
Sometimes that related record may be a little big or cumbersome to be handled in a modal and it may be quicker or simpler to redirect and create the record using the Resource's Create page.
Let's say we have a
Customer Resource with an
First we need to use the
CreateAction() on the
use Filament\Tables\Actions\CreateAction;CreateAction::make()->url(fn ($livewire) => InvoiceResource::getUrl('create', ['ownerRecord' => $livewire->ownerRecord->getKey()]))
Note that we pass in the calling customer's record key as a query param to our URL
['ownerRecord' => $this->ownerRecord->getKey()]
We can now pre-populate the Customer
BelongsToSelect on the
by studiowizjo, 7 months ago
by Hatim El Oufir, 4 months ago
I got "Using $this when not in object context"
any idea? thanks
btw, another workaround is get the key from url request()->segment(3)
BelongsToSelect is deprecated right now the same sample code using relationship()
Forms\Components\Select::make('customer_id') ->relationship('custumer', 'name') ->default(request()->query('ownerRecord'))
We detected that request()->query('ownerRecord') returns null after selecting the action create & create another.
Hi, after reactive(), request()->query('ownerRecord') return Null, how to solve this problem.
Hi Audruis! Our solution is to look for the query parameter ownerRecord in the previus url. url()->previous();