How to prevent passing invalid record ID to custom resource page URL in Filament?
Hi everyone,
I have a custom page in Filament that lists exams and quizzes, and a custom resource page for quizzes where the user can take the quiz. However, whenever I pass a $record to the URL of the custom resource page that does not exist in the database, the page still loads, which should not be the case. Can someone please advise on how I can ensure that the custom resource page only loads if the $record exists in the database? Thank you.
5 Replies
If you are redirecting from Resource to a Page. In the page mount() method you can do
Model::findOrFail($recordId)
Where should i define the $recordId variable?
I think it should be passed in mount. If not, maybe you can get it from request()
since it's in the url
Probably something like this:
Thank you both. It works now. Really appreciate