bavix / laravel-wallet

It's easy to work with a virtual wallet
https://bavix.github.io/laravel-wallet/
MIT License
1.15k stars 230 forks source link

How can i get transaction with different date between #133

Closed mustafasayilan closed 4 years ago

mustafasayilan commented 4 years ago

i am sorry i am a new on laravel and bavix wallet. I need get a list of transaction with auth roles i am using spatie permission for roles, forexample i have a role "cashier" and it have some transactions (withdraw and deposit) i need get its transaction list with date. I have tried "whereBeetwen" for transaction but its not working for me, Thanks for response and wallet...

krutyosila commented 4 years ago

hello, you can get all transactions list with $user->transactions; but I can't find paginate or search any data or between dates for transactions. I can create new model for transactions, but I couldn't connected to relationship.

krutyosila commented 4 years ago

I found it,

use Bavix\Wallet\Models\Transaction; $transactions = Transaction::where('payable_id',$user_id)->paginate(5);

mustafasayilan commented 4 years ago

I found it,

use Bavix\Wallet\Models\Transaction; $transactions = Transaction::where('payable_id',$user_id)->paginate(5);

Thank you for response to me. I think it will be work but its havent any date for filter... i need some more help.

For example, I have a role called "Customer." I want to list the transaction of all users with the customer role. Is it possible with relations ?

krutyosila commented 4 years ago

You can use Eloquent.

create new controller " TransactionController.php "

<?php

namespace App\Http\Controllers;

use Bavix\Wallet\Models\Transaction;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class TransactionController extends Controller
{
    public function getTransactions()
    {
        $transactions = Transaction::where('payable_id', Auth::id()) // Auth::id() is logged user id
            ->orderBy('created_at', 'DESC')
            ->paginate(20);
        dd($transactions);
    }

}

Add route for testing. Route::get('transactions', 'TransactionController@getTransactions');

mustafasayilan commented 4 years ago

You can use Eloquent.

create new controller " TransactionController.php "

<?php

namespace App\Http\Controllers;

use Bavix\Wallet\Models\Transaction;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class TransactionController extends Controller
{
    public function getTransactions()
    {
        $transactions = Transaction::where('payable_id', Auth::id()) // Auth::id() is logged user id
            ->orderBy('created_at', 'DESC')
            ->paginate(20);
        dd($transactions);
    }

}

Add route for testing. Route::get('transactions', 'TransactionController@getTransactions');

Thanks Ali, But maybe i can be clear a little more. Ofcorse i want use Eloquent. i have 2 date and i want get transactions beetween this dates with role or user id ,

Like this "Role of Customer or user id x 06.01.2020 beetween 07.01.2020 "

krutyosila commented 4 years ago
$from = date('2020-01-06');
$to = date('2020-01-07');

->whereBetween('created_at', [$from, $to])
mustafasayilan commented 4 years ago
$from = date('2020-01-06');
$to = date('2020-01-07');

->whereBetween('created_at', [$from, $to])

It is solved to my problems. Thank you Ali.

krutyosila commented 4 years ago

Hello again mustafa,

you can only transactions function for elequent queries, You can't need use Transactions model.

$user = Auth::user(); // or another user
$from = date('2020-01-06');
$to = date('2020-01-07');
$user->transactions()
            ->whereBetween('created_at', [$from, $to])
            ->orderBy('created_at', 'DESC')
            ->paginate(20);