Reputation: 1599
Hello I have no idea to ask this question, I have model Transaction that contains the amount the operator of the transaction, for example
Amount | Operator | Transaction ID |
---|---|---|
100 | add | 1234 |
100 | sub | 1234 |
333 | sub | 1235 |
555 | sub | 1236 |
444 | sub | 1237 |
I want to retrieve using eloquent the transaction with operator "sub" but not "add" so I want to retrieve only these records
Amount | Operator | Transaction ID |
---|---|---|
333 | sub | 1235 |
555 | sub | 1236 |
444 | sub | 1237 |
Upvotes: 0
Views: 45
Reputation: 830
you can do this :-
Transaction::where('operator','sub')
->whereNotIn('transaction_id', function($query) {
$query->select('transaction_id')
->from('transactions')
->where('operator','add');
})->get();
Upvotes: 3