|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yajra\Address\Repositories\Cities; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Cache\Repository as Cache; |
|
6
|
|
|
|
|
7
|
|
|
class CachingCitiesRepository extends CitiesRepositoryEloquent implements CitiesRepository |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var CitiesRepository |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $repository; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var \Illuminate\Contracts\Cache\Repository |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $cache; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* CachingCitiesRepository constructor. |
|
21
|
|
|
* |
|
22
|
|
|
* @param CitiesRepository $repository |
|
23
|
|
|
* @param Cache $cache |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct(CitiesRepository $repository, Cache $cache) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->repository = $repository; |
|
28
|
|
|
$this->cache = $cache; |
|
29
|
|
|
|
|
30
|
|
|
parent::__construct(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Get cities by region ID and province ID. |
|
35
|
|
|
* |
|
36
|
|
|
* @param int $regionId |
|
37
|
|
|
* @param int $provinceId |
|
38
|
|
|
* @return \Illuminate\Database\Eloquent\Collection |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getByProvinceAndRegion($regionId, $provinceId) |
|
41
|
|
|
{ |
|
42
|
|
|
$key = "cities.{$regionId}.{$provinceId}"; |
|
43
|
|
|
|
|
44
|
|
|
return $this->cache->rememberForever($key, function () use ($regionId, $provinceId) { |
|
45
|
|
|
return $this->repository->getByProvinceAndRegion($regionId, $provinceId); |
|
46
|
|
|
}); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get cities by province. |
|
51
|
|
|
* |
|
52
|
|
|
* @param int $provinceId |
|
53
|
|
|
* @return \Illuminate\Database\Eloquent\Collection |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getByProvince($provinceId) |
|
56
|
|
|
{ |
|
57
|
|
|
$key = "cities.{$provinceId}"; |
|
58
|
|
|
|
|
59
|
|
|
return $this->cache->rememberForever($key, function () use ($provinceId) { |
|
60
|
|
|
return $this->repository->getByProvince($provinceId); |
|
61
|
|
|
}); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get cities by region. |
|
66
|
|
|
* |
|
67
|
|
|
* @param int $regionId |
|
68
|
|
|
* @return \Illuminate\Database\Eloquent\Collection |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getByRegion($regionId) |
|
71
|
|
|
{ |
|
72
|
|
|
$key = "cities.region.{$regionId}"; |
|
73
|
|
|
|
|
74
|
|
|
return $this->cache->rememberForever($key, function () use ($regionId) { |
|
75
|
|
|
return $this->repository->getByRegion($regionId); |
|
76
|
|
|
}); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|