F
Filamentβ€’9mo ago
Chriis

Using $record into beforeCreate() method

Hi everyone, I want to generate a PDF when a user creates a resource, but I'm not sure where to place this logic. I need to have the $record available to pass it to the view used for generating the PDF, and I also need to do this before the record is saved into the database (to save the document path). After some research in the documentation, I found the lifecycle hook beforeCreate(). However, the fact that the method takes no arguments poses an issue for using $record. So, what would be the best way to accomplish this ? Help would appreciated πŸ™‚
2 Replies
ChesterS
ChesterSβ€’9mo ago
@Chriis I don't really use Resources for my project, so I'm not very familiar with it, but there is ena example here https://filamentphp.com/docs/3.x/panels/resources/creating-records#halting-the-creation-process where it uses $this->getRecord() to access the record. Does this not work?
Chriis
Chriisβ€’9mo ago
Yes it worked thanks πŸ™‚ Actually idk if i'm going to use lifecylce hook, I think events are better for handling this but for know I can test the generation with it. Good to know