/
TransactionRepository.php
35 lines (29 loc) · 1.2 KB
/
TransactionRepository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
namespace App\Repositories;
use App\Contracts\TransactionRepository as Contract;
use App\Models\Transaction;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
final class TransactionRepository implements Contract
{
public function allByWallet(string $address, string $publicKey): Collection
{
return Transaction::query()
->where(fn ($query): Builder => $query->where('sender_public_key', $publicKey))
->orWhere(fn ($query): Builder => $query->where('recipient_id', $address))
->orWhere(fn ($query): Builder => $query->whereJsonContains('asset->payments', [['recipientId' => $address]]))
->get();
}
public function allBySender(string $publicKey): Collection
{
return Transaction::where('sender_public_key', $publicKey)->get();
}
public function allByRecipient(string $address): Collection
{
return Transaction::query()
->orWhere(fn ($query): Builder => $query->where('recipient_id', $address))
->orWhere(fn ($query): Builder => $query->whereJsonContains('asset->payments', [['recipientId' => $address]]))
->get();
}
}