Importer: beforesave() hook check
good day, i want to make the following code possible
is it correct? because i tried it and it didn't work. how do i make it better?
2 Replies
Did you ever get a response on this one? I'm running into a similar problem. I'm wondering if it's because the importer is running as a service and doesn't have a auth()->user?
@HeartlandTechie I resolved it like this in XImporter.php
public function resolveRecord(): ?Voucher
{
$product = Product::where('slug', $this->data['slug'])->first();
if (!is_null($product))
{
return new Voucher([
'serial_voucher' => $this->data['serial_voucher'],
'product_id' => $product->id,
'created_by' => Auth::id(),
]);
}
return null;
}