skip to Main Content

Laravel filament has afterCreate function that will trigger after data has been stored in the database

protected function afterCreate(): void
{
   // Runs after the form fields are saved to the database.
}

The question is, how do I get the ‘stored’ data? I need to save a log for it (in the different table) that require the id of the stored data

2

Answers


  1. You can access the created record with $this->record.

    Also, this property is available in EditRecord.

    Here’s an example from the filament itself.

    Login or Signup to reply.
  2. use this to access data:

    protected function afterCreate(): void
    {
    
        $storedDataId = $this->record->getKey();
        
        $storedDataField = $this->record->yourFieldName;
    
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search