mpaannddreew / laravel-ledger

A simple ledger implementation for laravel 5 applications
28 stars 13 forks source link

Credits and Debits and Entries #6

Open adriangoris opened 5 years ago

adriangoris commented 5 years ago

I can insert credits and debits into the table and retrieve the balance, but i cannot retrieve the entries. It appears that entries are not being returned from withing the contoller.

public function show(Account $account, $id)
{
    $account = Account::find($id);
    $entries = $account->entries();
    $debits = $account->debits();
    $credits = $account->credits();
    $balance = $account->balance();
    return response()->json([
            'status'=>200,
            'type'=>'GET',
            'message'=>'OK: Successfully retrieved Account',
            'data'=>$account,
            'debits'=>$debits,
            'credits'=>$credits,
            'balance'=>$balance
    ]);
}
adriangoris commented 5 years ago

In order to get it working in the meantime I added it to my accounts model:

public function entries() 
{ 
    return $this->morphMany('\FannyPack\Ledger\LedgerEntry', 'ledgerable'); 
}
mpaannddreew commented 5 years ago

Hello, you did not have to create this

public function entries() { return $this->morphMany('\FannyPack\Ledger\LedgerEntry', 'ledgerable'); }

because there is a trait that you add to your model that has all required functions. Go to this url to see what I mean. https://github.com/mpaannddreew/laravel-ledger#usage.

Thanks for the feedback.

On Tue, Mar 19, 2019 at 1:24 AM Adrian notifications@github.com wrote:

In order to get it working in the meantime I added it to my accounts model:

public function entries() { return $this->morphMany('\FannyPack\Ledger\LedgerEntry', 'ledgerable'); }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mpaannddreew/laravel-ledger/issues/6#issuecomment-474124897, or mute the thread https://github.com/notifications/unsubscribe-auth/AJxBX7QwGFUsau72vPDecTLB54Fzqvokks5vYBI3gaJpZM4b63fu .