Update source into github
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace App\Repositories\Transaction;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class TransactionCachedRepository extends BaseCachedRepository implements TransactionRepositoryInterface {
|
||||
public function __construct(
|
||||
public TransactionRepository $transactionRepository
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
public function getModel()
|
||||
{
|
||||
return $this->transactionRepository->getModel();
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'filterItem' => [
|
||||
'data' => $data,
|
||||
'relationships' => $relationships,
|
||||
'select' => $select,
|
||||
'withCount' => $withCount
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($data, $relationships, $select, $withCount) {
|
||||
return $this->transactionRepository->filter($data, $relationships, $withCount, $select);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace App\Repositories\Transaction;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface TransactionRepositoryInterface extends BaseRepositoryInterface{
|
||||
public function filter(array $data = [],array $relationships = [],array $withCount = [],array $select = ['*']);
|
||||
}
|
||||
Reference in New Issue
Block a user