33 lines
1000 B
PHP
33 lines
1000 B
PHP
<?php
|
|
|
|
namespace App\Repositories\Transaction;
|
|
|
|
use App\Models\Transaction;
|
|
use App\Repositories\BaseRepository;
|
|
|
|
class TransactionRepository extends BaseRepository implements TransactionRepositoryInterface
|
|
{
|
|
public function getModel()
|
|
{
|
|
return Transaction::class;
|
|
}
|
|
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
|
|
{
|
|
$model = $this->model->with($relationships)->select($select);
|
|
if (isset($data['customer_id']) && ! empty($data['customer_id'])) {
|
|
$model = $model->where("customer_id", $data['customer_id']);
|
|
}
|
|
|
|
if (count($withCount) > 0) {
|
|
$model = $model->withCount($withCount);
|
|
}
|
|
if (isset($data['limit']) && $data['limit']) {
|
|
return $model->latest('id')->take($data['limit'])->get();
|
|
}
|
|
if (isset($data['page'])) {
|
|
return $model->paginate(15);
|
|
}
|
|
return $model->get();
|
|
}
|
|
}
|