May 27, 2024
0
Level 1
When are HOOKS in Filament really called?
In reaction to the Error, I have described in "How can I prevent an Exception if the Select-Options in a relationship has a NULL value?" I tried to use Hooks to fill missing values in 'working_name' as:
protected function beforeFill(): void
{
// Runs before the form fields are populated from the database.
$toBeUpdatedOnes = Project::whereNull('working_name')->get();
\Log::info('EDIT beforeFill found records ', $toBeUpdatedOnes); // Log the incoming data
foreach ($toBeUpdatedOnes as $toBeUpdated) {
\Log::info('beforeFill found record ', [$toBeUpdated]); // Log the incoming data
$text = 'missing working name';
if ($toBeUpdated->description == null) {
$text = $text . ', ID: ' . str($toBeUpdated->id);
} else {
$text = $toBeUpdated->description;
if (strlen($text) > 120) {
$text = substr($text, 0, 120);
}
}
$toBeUpdated->update(['working_name' => $text]);
\Log::info('beforeFill updated record ', [$toBeUpdated]); // Log the corrected data
}
}
I have seen the LOG-Entry once, but only once. The other times I got the above mentioned Error. That means for me, the OPTIONS-List is created before the FILL. I even tried it with mount() but with the same (Error-) Result. So I am not sure, whether and when the HOOKS are called.
Please or to participate in this conversation.