Wednesday, April 12, 2017

Eloquent with not working

Hello I am having this problem with the laravel eloquent with. This code (in the docs) $debtHistory = DebtHistory::with('user.firstname')->get(); seems to not work, because it returns something lik Call to undefined relationship [firstname] on model [App\User]. what am I doing wrong here? Any idea? Thank you guys. :)

Note: If this helps.

I actually have an alternative method but I would like to do it in one query. This code my help you to know what I am trying to do.

$debtHistory = DebtHistory::whereBetween('created_at',[$filterData['from'], $filterData['to']])->where('amount', '>', '0')->get();
$excelData = [];
foreach($debtHistory as $history) {
     array_push($excelData, ['Name' => $history->user->firstname .' '. $history->user->lastname, 'Debt' => $history->amount, 'Date' => Carbon::parse($history->created_at)->format('Y-m-d')]);
}

I want to do that process in a eloquent model query is that possible?



via Keannu Alforque Atilano

Advertisement