I am using laravel excel to export my data. Inside map function, the $credit and $debit variables but when returning them, it throws a error.
The error is :
Trying to get property 'name' of non-object
here is my map function:
public function map($partner): array
{
$credit = Bank::whereId($partner->credit)->first(); // also used: Bank::find($partner->credit);
$debit = Bank::whereId($partner->debit)->first();
dd($credit->name) // returns 'test'
return [
$partner->full_name, // this returns correctly.
$credit->name, // returns "Trying to get property 'name' of non-object"
// if use $credit, it returns whole credit object.
$debit->name, // returns "Trying to get property 'name' of non-object"
// if use $credit, it returns whole debit object.
];
}