assertRedirect to a URL with an ID when testing
Here's my Pest code which I write by looking at both the FilamentPHP and Livewire testing docs:
This fails saying,
Missing required parameter for [Route: filament.admin.resources.posts.view] [URI: admin/posts/{record}] [Missing parameter: record]
There doesn't seem to be a way to pass a param to this, so I changed it slightly:
Ok, that works. But obviously I'm hardcoding the ID. How am I supposed to get the ID when filling a form like this so that I can assert that it redirected to the correct route dynamically?Solution:Jump to solution
Query for the latest post. Then you’ll have the id from the create method.
For the redirect you should use
PostResource::getUrl(‘view’, [‘record’ => $post])...
2 Replies
Solution
Query for the latest post. Then you’ll have the id from the create method.
For the redirect you should use
PostResource::getUrl(‘view’, [‘record’ => $post])
Nice, thank you! Answers both of my questions 🙂
Here's what I ended up with... I'm posting it here in case it helps anyone else or in case I forget and search again in a few weeks 🤪