F
Filament2y ago
qcol

handleRecordCreation

Depending on the condition, a result of true performs a standard write of the record to the database, a result of false should only display a message without writing to the database. However, after displaying the message only, I get an error because the function expects a model to be returned. How do I handle this?
3 Replies
toeknee
toeknee2y ago
IF you have a null data column where it is not supposed to be, your schema is not setup correctly, or your model attributes and casts are not properly defined
qcol
qcolOP2y ago
Everything is OK with my database. My question is just what to return in the handleRecordCreation function if it doesn't write anything to the database. Since the function is used to change the behaviour of the process, I would expect that in certain situations there would be no writing to the database, just a message (which is the case for me). If the function only ends with a message, I get an error "function expects a model to be returned" protected function handleRecordCreation(array $data): \Illuminate\Database\Eloquent\Model { if ($data['set_id'] !== null) { //a lot of code here return static::getModel()::create($data); } else { // here is problem \Filament\Notifications\Notification::make() ->warning() ->title('Title') ->body('body txt.') ->persistent()
->send(); } ;
}
toeknee
toeknee2y ago
You can do a try or a catch, but why would that matter? You can just test if something has changed prior to save
Want results from more Discord servers?
Add your server