issue with fillrecordusing
I am trying to ensure that nothing other than "Yes" or "No" goes through my importer class, and i am doing that using the below code. But the value is passed in DB as it comes and is not changed as per the logic below.
ImportColumn::make('item_loaned')
->requiredMapping()
->fillRecordUsing(function (Inventory $record, string $state): void {
if(strtolower($state) === 'yes')
{
$record->item_loaned = 'Yes';
}
elseif (strtolower($state) === 'no') {
$record->item_loaned = 'No';
}
})
->rules(['required', 'max:255'])
2 Replies
Wouldn't a setter on the model fit this better?.
It is very surprising that this code did not worked on my Local machine, but when i hosted it on server, it worked absolutely fine.
here is the code snippet
ImportColumn::make('item_loaned')
->requiredMapping()
->fillRecordUsing(function (Inventory $record, string $state): void {
if(strtolower($state) === 'yes')
{
$record->item_loaned = 'Yes';
}
elseif (strtolower($state) === 'no') {
$record->item_loaned = 'No';
}
else {
$record->item_loaned = 'No';
}
})
->rules(['required', 'max:255']),