F
Filament13mo ago
Bagus A

How to know what arguments available inside a function?

I'm sure it's not Filament only question, it might closely related to the PHP itself. For example, I would like to pre-process the data before saving it to the database. In this case I need to use before lifecycle hook for a CreateAction. I want to know how I can get the current form data inside this callback. Documentation example show the function without any arguments.
->before(function () {
// Runs before the form fields are saved to the database.
})
->before(function () {
// Runs before the form fields are saved to the database.
})
While, other example show it with two arguments

->before(function (CreateAction $action, Post $record) {}

->before(function (CreateAction $action, Post $record) {}
If I use my text editor to see inside before declaration inside HasLifeCycleHook.php it only has Closure.
public function before(Closure $callback): static
{
$this->before = $callback;

return $this;
}
public function before(Closure $callback): static
{
$this->before = $callback;

return $this;
}
I still don't understand how do I realize that any function in Filament can receive what kind of data? Appreciate every information. Thank you guys.
1 Reply
Dennis Koch
Dennis Koch13mo ago
I think it’s mentioned in some part of the docs. Most of the time it’s the same params that are injected. They are defined in the defaultEvaluationParameters() method of the components. For your usecase I think there is a mutateDataBeforeSave() or similar method which would be more appropriate.
Want results from more Discord servers?
Add your server