Answer the question
In order to leave comments, you need to log in
How to get only unique data from DB in Laravel?
The bottom line is that there is a table in the database, there are two important columns, these are "traiff_id" and "status"
Model::where([
['status', '=', 'CLOSED'],
['user_id', '=', $user->id]
])
->get()
->groupBy('id')
->toArray();
id tariff_id status
1 1 CLOSED
2 1 ACTIVE
3 2 CLOSED
Answer the question
In order to leave comments, you need to log in
I don't know how to pull out unique requests to the database. Probably easy and googling. In a collection, you can use the unique() method . If Model is of type Payment, then in User you need to make a hasMany relation
public function payments() {
return $this->hasMany('App\Models\Payment','user_id', 'id');
}
$status = 'CLOSED';
$payments = $user->payments()
->where('status', $status)
->get()
->unique('tariff_id');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question