How to modify "Create Another" action in Filament to include a query parameter based on a form field

Question: I'm using FilamentPHP and I want to enhance the "Create Another" behavior when creating a resource (e.g., Product). Specifically, I'd like to redirect to the create page again, but with a query parameter (e.g., ?store_id=123) taken from the currently submitted form field (store_id). My goal is to make it easier for users who are adding multiple products to the same store consecutively. How can I modify the "Create Another" functionality in a custom CreateRecord page (like CreateProduct) to append this query parameter after saving? Any best practices or recommended approach? Use Case Example: * User selects a store (store_id = 5) while creating a product. * After saving and clicking "Create Another", the user is redirected to /admin/products/create?store_id=5, so the store_id field is pre-filled for the next product. Thanks in advance!
1 Reply
toeknee
toeknee4w ago
Why not set it on loading the page and get it from the session on each load set the session value as null unless it exists in the url? This would go in the CreatePage.php I.e.
public function mount($id) {
parent::mount($id);
session()->put('store_id', request()->get('store_id', null));
}
public function mount($id) {
parent::mount($id);
session()->put('store_id', request()->get('store_id', null));
}
Free hand, so might not work but basis is there.

Did you find this page helpful?