Update source into github
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Mail;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class MailCachedRepository extends BaseCachedRepository implements MailRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
public MailRepository $mailRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
public function getModel()
|
||||
{
|
||||
return $this->mailRepository->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->mailRepository->filter($data, $relationships, $withCount, $select);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Mail;
|
||||
|
||||
use App\Models\Mail;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class MailRepository extends BaseRepository implements MailRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return Mail::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['page'])) {
|
||||
return $model->paginate(15);
|
||||
}
|
||||
return $model->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace App\Repositories\Mail;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface MailRepositoryInterface extends BaseRepositoryInterface{
|
||||
public function filter(array $data = [],array $relationships = [],array $withCount = [],array $select = ['*']);
|
||||
}
|
||||
Reference in New Issue
Block a user