jeudi 8 mars 2018

Laravel 5 Eloquent join 2 table got Property [tradeHistories] does not exist on this collection instance

I have a problem here, and I don't have any idea why it's happened, because I followed the tutorial on youtube precisely.

Here is the problem:

Account.php

#region Relationship: one to many
public function tradeHistories() {
    return $this->hasMany('App\TradeHistory');
}
#endregion

TradeHistory.php

#region Relationship: one to many (reversed)
public function account() {
    return $this->belongsTo('App\Account');
}
#endregion

AccountsController.php

public function index()
{
    $accounts = Account::all();
    dd($accounts->tradeHistories);
    return view('pages.account.index')
            ->with('active', 'account')
            ->with('accounts', $accounts);
}

In returns I got this message

"Property [tradeHistories] does not exist on this collection instance."

So why I got that message? because I want to show all the trade histories for all account.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2D8Hopd
via IFTTT

Aucun commentaire:

Enregistrer un commentaire