@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class Media extends Facade |
6 | 6 | { |
7 | - protected static function getFacadeAccessor() |
|
8 | - { |
|
9 | - return 'Media'; |
|
10 | - } |
|
7 | + protected static function getFacadeAccessor() |
|
8 | + { |
|
9 | + return 'Media'; |
|
10 | + } |
|
11 | 11 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class Core extends Facade |
6 | 6 | { |
7 | - protected static function getFacadeAccessor() |
|
8 | - { |
|
9 | - return 'Core'; |
|
10 | - } |
|
7 | + protected static function getFacadeAccessor() |
|
8 | + { |
|
9 | + return 'Core'; |
|
10 | + } |
|
11 | 11 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class ApiConsumer extends Facade |
6 | 6 | { |
7 | - protected static function getFacadeAccessor() |
|
8 | - { |
|
9 | - return 'ApiConsumer'; |
|
10 | - } |
|
7 | + protected static function getFacadeAccessor() |
|
8 | + { |
|
9 | + return 'ApiConsumer'; |
|
10 | + } |
|
11 | 11 | } |
@@ -2,17 +2,17 @@ |
||
2 | 2 | |
3 | 3 | class CoreConfig |
4 | 4 | { |
5 | - public function getConfig() |
|
6 | - { |
|
7 | - return [ |
|
8 | - /** |
|
9 | - * Specify what relations should be used for every model. |
|
10 | - */ |
|
11 | - 'relations' => config('skeleton.relations'), |
|
12 | - /** |
|
13 | - * Specify caching config for each api. |
|
14 | - */ |
|
15 | - 'cacheConfig' => config('skeleton.cache_config'), |
|
16 | - ]; |
|
17 | - } |
|
5 | + public function getConfig() |
|
6 | + { |
|
7 | + return [ |
|
8 | + /** |
|
9 | + * Specify what relations should be used for every model. |
|
10 | + */ |
|
11 | + 'relations' => config('skeleton.relations'), |
|
12 | + /** |
|
13 | + * Specify caching config for each api. |
|
14 | + */ |
|
15 | + 'cacheConfig' => config('skeleton.cache_config'), |
|
16 | + ]; |
|
17 | + } |
|
18 | 18 | } |
@@ -2,62 +2,62 @@ |
||
2 | 2 | |
3 | 3 | class Media |
4 | 4 | { |
5 | - /** |
|
6 | - * Upload the given image. |
|
7 | - * |
|
8 | - * @param object $image |
|
9 | - * @param string $dir |
|
10 | - * @return string |
|
11 | - */ |
|
12 | - public function uploadImage($image, $dir) |
|
13 | - { |
|
14 | - $image = \Image::make($image); |
|
15 | - return $this->saveImage($image, $dir); |
|
16 | - } |
|
5 | + /** |
|
6 | + * Upload the given image. |
|
7 | + * |
|
8 | + * @param object $image |
|
9 | + * @param string $dir |
|
10 | + * @return string |
|
11 | + */ |
|
12 | + public function uploadImage($image, $dir) |
|
13 | + { |
|
14 | + $image = \Image::make($image); |
|
15 | + return $this->saveImage($image, $dir); |
|
16 | + } |
|
17 | 17 | |
18 | - /** |
|
19 | - * Upload the given image. |
|
20 | - * |
|
21 | - * @param object $image |
|
22 | - * @param string $dir |
|
23 | - * @return string |
|
24 | - */ |
|
25 | - public function uploadImageBas64($image, $dir) |
|
26 | - { |
|
27 | - if (! strlen($image)) { |
|
28 | - return null; |
|
29 | - } |
|
18 | + /** |
|
19 | + * Upload the given image. |
|
20 | + * |
|
21 | + * @param object $image |
|
22 | + * @param string $dir |
|
23 | + * @return string |
|
24 | + */ |
|
25 | + public function uploadImageBas64($image, $dir) |
|
26 | + { |
|
27 | + if (! strlen($image)) { |
|
28 | + return null; |
|
29 | + } |
|
30 | 30 | |
31 | - $base = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image)); |
|
32 | - $image = \Image::make($base); |
|
31 | + $base = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image)); |
|
32 | + $image = \Image::make($base); |
|
33 | 33 | |
34 | - return $this->saveImage($image, $dir); |
|
35 | - } |
|
34 | + return $this->saveImage($image, $dir); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Delete the given image. |
|
39 | - * |
|
40 | - * @param object $path |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public function deleteImage($path) |
|
44 | - { |
|
45 | - \Storage::delete($path); |
|
46 | - } |
|
37 | + /** |
|
38 | + * Delete the given image. |
|
39 | + * |
|
40 | + * @param object $path |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public function deleteImage($path) |
|
44 | + { |
|
45 | + \Storage::delete($path); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Save the given image. |
|
50 | - * |
|
51 | - * @param object $image |
|
52 | - * @param string $dir |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - protected function saveImage($image, $dir) |
|
56 | - { |
|
57 | - $imageName = 'image'.uniqid().time().'.jpg'; |
|
58 | - $path = 'public'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$imageName; |
|
59 | - \Storage::put($path, $image->stream()); |
|
48 | + /** |
|
49 | + * Save the given image. |
|
50 | + * |
|
51 | + * @param object $image |
|
52 | + * @param string $dir |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + protected function saveImage($image, $dir) |
|
56 | + { |
|
57 | + $imageName = 'image'.uniqid().time().'.jpg'; |
|
58 | + $path = 'public'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$imageName; |
|
59 | + \Storage::put($path, $image->stream()); |
|
60 | 60 | |
61 | - return $path; |
|
62 | - } |
|
61 | + return $path; |
|
62 | + } |
|
63 | 63 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | */ |
25 | 25 | public function uploadImageBas64($image, $dir) |
26 | 26 | { |
27 | - if (! strlen($image)) { |
|
27 | + if ( ! strlen($image)) { |
|
28 | 28 | return null; |
29 | 29 | } |
30 | 30 |
@@ -2,46 +2,46 @@ |
||
2 | 2 | |
3 | 3 | trait Translatable |
4 | 4 | { |
5 | - /** |
|
6 | - * Create a new model instance that is existing. |
|
7 | - * |
|
8 | - * @param array $attributes |
|
9 | - * @param string|null $connection |
|
10 | - * @return static |
|
11 | - */ |
|
12 | - public function newFromBuilder($attributes = [], $connection = null) |
|
13 | - { |
|
14 | - $model = parent::newFromBuilder($attributes, $connection); |
|
5 | + /** |
|
6 | + * Create a new model instance that is existing. |
|
7 | + * |
|
8 | + * @param array $attributes |
|
9 | + * @param string|null $connection |
|
10 | + * @return static |
|
11 | + */ |
|
12 | + public function newFromBuilder($attributes = [], $connection = null) |
|
13 | + { |
|
14 | + $model = parent::newFromBuilder($attributes, $connection); |
|
15 | 15 | |
16 | - foreach ($model->attributes as $key => $value) { |
|
17 | - if (isset($this->translatable) && in_array($key, $this->translatable)) { |
|
18 | - $model->$key = $this->getTranslatedAttribute($value); |
|
19 | - } |
|
20 | - } |
|
16 | + foreach ($model->attributes as $key => $value) { |
|
17 | + if (isset($this->translatable) && in_array($key, $this->translatable)) { |
|
18 | + $model->$key = $this->getTranslatedAttribute($value); |
|
19 | + } |
|
20 | + } |
|
21 | 21 | |
22 | - return $model; |
|
23 | - } |
|
22 | + return $model; |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Returns a translatable model attribute based on the application's locale settings. |
|
27 | - * |
|
28 | - * @param $values |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - protected function getTranslatedAttribute($values) |
|
32 | - { |
|
33 | - $values = json_decode($values); |
|
34 | - $primaryLocale = \Session::get('locale'); |
|
35 | - $fallbackLocale = 'en'; |
|
25 | + /** |
|
26 | + * Returns a translatable model attribute based on the application's locale settings. |
|
27 | + * |
|
28 | + * @param $values |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + protected function getTranslatedAttribute($values) |
|
32 | + { |
|
33 | + $values = json_decode($values); |
|
34 | + $primaryLocale = \Session::get('locale'); |
|
35 | + $fallbackLocale = 'en'; |
|
36 | 36 | |
37 | - if ($primaryLocale == 'all') { |
|
38 | - return $values; |
|
39 | - } |
|
37 | + if ($primaryLocale == 'all') { |
|
38 | + return $values; |
|
39 | + } |
|
40 | 40 | |
41 | - if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
42 | - return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : ''; |
|
43 | - } |
|
41 | + if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
42 | + return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : ''; |
|
43 | + } |
|
44 | 44 | |
45 | - return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
46 | - } |
|
45 | + return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
46 | + } |
|
47 | 47 | } |
@@ -38,7 +38,7 @@ |
||
38 | 38 | return $values; |
39 | 39 | } |
40 | 40 | |
41 | - if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
41 | + if ( ! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
42 | 42 | return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : ''; |
43 | 43 | } |
44 | 44 |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /** |
|
6 | - * Here goes your notification messages. |
|
7 | - */ |
|
5 | + /** |
|
6 | + * Here goes your notification messages. |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | ]; |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @param array $relations |
36 | 36 | * @param string $sortBy |
37 | - * @param boolean $desc |
|
37 | + * @param integer $desc |
|
38 | 38 | * @param array $columns |
39 | 39 | * @return collection |
40 | 40 | */ |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @param integer $perPage |
53 | 53 | * @param array $relations |
54 | 54 | * @param string $sortBy |
55 | - * @param boolean $desc |
|
55 | + * @param integer $desc |
|
56 | 56 | * @param array $columns |
57 | 57 | * @return collection |
58 | 58 | */ |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @param integer $perPage |
155 | 155 | * @param array $relations |
156 | 156 | * @param string $sortBy |
157 | - * @param boolean $desc |
|
157 | + * @param integer $desc |
|
158 | 158 | * @param array $columns |
159 | 159 | * @return collection |
160 | 160 | */ |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @param integer $perPage |
173 | 173 | * @param array $relations |
174 | 174 | * @param string $sortBy |
175 | - * @param boolean $desc |
|
175 | + * @param integer $desc |
|
176 | 176 | * @param array $columns |
177 | 177 | * @return collection |
178 | 178 | */ |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * Save the given model to the storage. |
189 | 189 | * |
190 | 190 | * @param array $data |
191 | - * @return mixed |
|
191 | + * @return boolean |
|
192 | 192 | */ |
193 | 193 | public function save(array $data) |
194 | 194 | { |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | * @param array $conditions array of conditions |
478 | 478 | * @param array $relations |
479 | 479 | * @param string $sortBy |
480 | - * @param boolean $desc |
|
480 | + * @param integer $desc |
|
481 | 481 | * @param array $columns |
482 | 482 | * @return collection |
483 | 483 | */ |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | * @param array $conditions array of conditions |
510 | 510 | * @param integer $perPage |
511 | 511 | * @param string $sortBy |
512 | - * @param boolean $desc |
|
512 | + * @param integer $desc |
|
513 | 513 | * @param array $columns |
514 | 514 | * @return collection |
515 | 515 | */ |
@@ -6,676 +6,676 @@ |
||
6 | 6 | |
7 | 7 | abstract class BaseRepository implements BaseRepositoryInterface |
8 | 8 | { |
9 | - /** |
|
10 | - * @var object |
|
11 | - */ |
|
12 | - public $model; |
|
9 | + /** |
|
10 | + * @var object |
|
11 | + */ |
|
12 | + public $model; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Init new object. |
|
16 | - * |
|
17 | - * @var mixed model |
|
18 | - * @return void |
|
19 | - */ |
|
20 | - public function __construct($model) |
|
21 | - { |
|
22 | - $this->model = $model; |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * Fetch records with relations based on the given params. |
|
27 | - * |
|
28 | - * @param string $relations |
|
29 | - * @param array $conditions |
|
30 | - * @param integer $perPage |
|
31 | - * @param string $sortBy |
|
32 | - * @param boolean $desc |
|
33 | - * @return collection |
|
34 | - */ |
|
35 | - public function list($relations = [], $conditions = false, $perPage = 15, $sortBy = 'created_at', $desc = true) |
|
36 | - { |
|
37 | - unset($conditions['perPage']); |
|
38 | - unset($conditions['sortBy']); |
|
39 | - unset($conditions['sort']); |
|
40 | - unset($conditions['page']); |
|
41 | - |
|
42 | - if (count($conditions)) { |
|
43 | - return $this->paginateBy(['and' => $conditions], $perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true); |
|
44 | - } |
|
45 | - |
|
46 | - return $this->paginate($perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true); |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Fetch all records with relations from the storage. |
|
51 | - * |
|
52 | - * @param array $relations |
|
53 | - * @param string $sortBy |
|
54 | - * @param boolean $desc |
|
55 | - * @param array $columns |
|
56 | - * @return collection |
|
57 | - */ |
|
58 | - public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
59 | - { |
|
60 | - $sort = $desc ? 'desc' : 'asc'; |
|
61 | - return $this->model->with($relations)->orderBy($sortBy, $sort)->get($columns); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Fetch all records with relations from storage in pages |
|
66 | - * that matche the given query. |
|
67 | - * |
|
68 | - * @param string $query |
|
69 | - * @param integer $perPage |
|
70 | - * @param array $relations |
|
71 | - * @param string $sortBy |
|
72 | - * @param boolean $desc |
|
73 | - * @param array $columns |
|
74 | - * @return collection |
|
75 | - */ |
|
76 | - public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
77 | - { |
|
78 | - $model = $this->model->with($relations); |
|
79 | - $conditionColumns = $this->model->searchable; |
|
80 | - $sort = $desc ? 'desc' : 'asc'; |
|
81 | - |
|
82 | - /** |
|
83 | - * Construct the select conditions for the model. |
|
84 | - */ |
|
85 | - $model->where(function ($q) use ($query, $conditionColumns, $relations) { |
|
86 | - |
|
87 | - if (count($conditionColumns)) { |
|
88 | - $column = 'LOWER('.array_shift($conditionColumns).')'; |
|
89 | - if (Str::contains($column, '->')) { |
|
90 | - $column = $this->wrapJsonSelector($column); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Use the first element in the model columns to construct the first condition. |
|
95 | - */ |
|
96 | - $q->where(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Loop through the rest of the columns to construct or where conditions. |
|
101 | - */ |
|
102 | - foreach ($conditionColumns as $column) { |
|
103 | - $column = 'LOWER('.$column.')'; |
|
104 | - if (Str::contains($column, '->')) { |
|
105 | - $column = $this->wrapJsonSelector($column); |
|
106 | - } |
|
107 | - |
|
108 | - $q->orWhere(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Loop through the model relations. |
|
113 | - */ |
|
114 | - foreach ($relations as $relation) { |
|
115 | - /** |
|
116 | - * Remove the sub relation if exists. |
|
117 | - */ |
|
118 | - $relation = explode('.', $relation)[0]; |
|
119 | - |
|
120 | - /** |
|
121 | - * Try to fetch the relation repository from the core. |
|
122 | - */ |
|
123 | - if (\Core::$relation()) { |
|
124 | - /** |
|
125 | - * Construct the relation condition. |
|
126 | - */ |
|
127 | - $q->orWhereHas($relation, function ($subModel) use ($query, $relation) { |
|
128 | - |
|
129 | - $subModel->where(function ($q) use ($query, $relation) { |
|
130 | - |
|
131 | - /** |
|
132 | - * Get columns of the relation. |
|
133 | - */ |
|
134 | - $subConditionColumns = \Core::$relation()->model->searchable; |
|
135 | - |
|
136 | - if (count($subConditionColumns)) { |
|
137 | - $column = 'LOWER('.array_shift($subConditionColumns).')'; |
|
138 | - if (Str::contains($column, '->')) { |
|
139 | - $column = $this->wrapJsonSelector($column); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Use the first element in the relation model columns to construct the first condition. |
|
144 | - */ |
|
145 | - $q->where(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Loop through the rest of the columns to construct or where conditions. |
|
150 | - */ |
|
151 | - foreach ($subConditionColumns as $subConditionColumn) { |
|
152 | - $column = 'LOWER('.$subConditionColumn.')'; |
|
153 | - if (Str::contains($column, '->')) { |
|
154 | - $column = $this->wrapJsonSelector($column); |
|
155 | - } |
|
14 | + /** |
|
15 | + * Init new object. |
|
16 | + * |
|
17 | + * @var mixed model |
|
18 | + * @return void |
|
19 | + */ |
|
20 | + public function __construct($model) |
|
21 | + { |
|
22 | + $this->model = $model; |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * Fetch records with relations based on the given params. |
|
27 | + * |
|
28 | + * @param string $relations |
|
29 | + * @param array $conditions |
|
30 | + * @param integer $perPage |
|
31 | + * @param string $sortBy |
|
32 | + * @param boolean $desc |
|
33 | + * @return collection |
|
34 | + */ |
|
35 | + public function list($relations = [], $conditions = false, $perPage = 15, $sortBy = 'created_at', $desc = true) |
|
36 | + { |
|
37 | + unset($conditions['perPage']); |
|
38 | + unset($conditions['sortBy']); |
|
39 | + unset($conditions['sort']); |
|
40 | + unset($conditions['page']); |
|
41 | + |
|
42 | + if (count($conditions)) { |
|
43 | + return $this->paginateBy(['and' => $conditions], $perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true); |
|
44 | + } |
|
45 | + |
|
46 | + return $this->paginate($perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true); |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Fetch all records with relations from the storage. |
|
51 | + * |
|
52 | + * @param array $relations |
|
53 | + * @param string $sortBy |
|
54 | + * @param boolean $desc |
|
55 | + * @param array $columns |
|
56 | + * @return collection |
|
57 | + */ |
|
58 | + public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
59 | + { |
|
60 | + $sort = $desc ? 'desc' : 'asc'; |
|
61 | + return $this->model->with($relations)->orderBy($sortBy, $sort)->get($columns); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Fetch all records with relations from storage in pages |
|
66 | + * that matche the given query. |
|
67 | + * |
|
68 | + * @param string $query |
|
69 | + * @param integer $perPage |
|
70 | + * @param array $relations |
|
71 | + * @param string $sortBy |
|
72 | + * @param boolean $desc |
|
73 | + * @param array $columns |
|
74 | + * @return collection |
|
75 | + */ |
|
76 | + public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
77 | + { |
|
78 | + $model = $this->model->with($relations); |
|
79 | + $conditionColumns = $this->model->searchable; |
|
80 | + $sort = $desc ? 'desc' : 'asc'; |
|
81 | + |
|
82 | + /** |
|
83 | + * Construct the select conditions for the model. |
|
84 | + */ |
|
85 | + $model->where(function ($q) use ($query, $conditionColumns, $relations) { |
|
86 | + |
|
87 | + if (count($conditionColumns)) { |
|
88 | + $column = 'LOWER('.array_shift($conditionColumns).')'; |
|
89 | + if (Str::contains($column, '->')) { |
|
90 | + $column = $this->wrapJsonSelector($column); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Use the first element in the model columns to construct the first condition. |
|
95 | + */ |
|
96 | + $q->where(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Loop through the rest of the columns to construct or where conditions. |
|
101 | + */ |
|
102 | + foreach ($conditionColumns as $column) { |
|
103 | + $column = 'LOWER('.$column.')'; |
|
104 | + if (Str::contains($column, '->')) { |
|
105 | + $column = $this->wrapJsonSelector($column); |
|
106 | + } |
|
107 | + |
|
108 | + $q->orWhere(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Loop through the model relations. |
|
113 | + */ |
|
114 | + foreach ($relations as $relation) { |
|
115 | + /** |
|
116 | + * Remove the sub relation if exists. |
|
117 | + */ |
|
118 | + $relation = explode('.', $relation)[0]; |
|
119 | + |
|
120 | + /** |
|
121 | + * Try to fetch the relation repository from the core. |
|
122 | + */ |
|
123 | + if (\Core::$relation()) { |
|
124 | + /** |
|
125 | + * Construct the relation condition. |
|
126 | + */ |
|
127 | + $q->orWhereHas($relation, function ($subModel) use ($query, $relation) { |
|
128 | + |
|
129 | + $subModel->where(function ($q) use ($query, $relation) { |
|
130 | + |
|
131 | + /** |
|
132 | + * Get columns of the relation. |
|
133 | + */ |
|
134 | + $subConditionColumns = \Core::$relation()->model->searchable; |
|
135 | + |
|
136 | + if (count($subConditionColumns)) { |
|
137 | + $column = 'LOWER('.array_shift($subConditionColumns).')'; |
|
138 | + if (Str::contains($column, '->')) { |
|
139 | + $column = $this->wrapJsonSelector($column); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Use the first element in the relation model columns to construct the first condition. |
|
144 | + */ |
|
145 | + $q->where(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Loop through the rest of the columns to construct or where conditions. |
|
150 | + */ |
|
151 | + foreach ($subConditionColumns as $subConditionColumn) { |
|
152 | + $column = 'LOWER('.$subConditionColumn.')'; |
|
153 | + if (Str::contains($column, '->')) { |
|
154 | + $column = $this->wrapJsonSelector($column); |
|
155 | + } |
|
156 | 156 | |
157 | - $q->orWhere(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
158 | - } |
|
159 | - }); |
|
160 | - }); |
|
161 | - } |
|
162 | - } |
|
163 | - }); |
|
157 | + $q->orWhere(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
158 | + } |
|
159 | + }); |
|
160 | + }); |
|
161 | + } |
|
162 | + } |
|
163 | + }); |
|
164 | 164 | |
165 | - return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
166 | - } |
|
165 | + return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * Fetch all records with relations from storage in pages. |
|
170 | - * |
|
171 | - * @param integer $perPage |
|
172 | - * @param array $relations |
|
173 | - * @param string $sortBy |
|
174 | - * @param boolean $desc |
|
175 | - * @param array $columns |
|
176 | - * @return collection |
|
177 | - */ |
|
178 | - public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
179 | - { |
|
180 | - $sort = $desc ? 'desc' : 'asc'; |
|
181 | - return $this->model->with($relations)->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Fetch all records with relations based on |
|
186 | - * the given condition from storage in pages. |
|
187 | - * |
|
188 | - * @param array $conditions array of conditions |
|
189 | - * @param integer $perPage |
|
190 | - * @param array $relations |
|
191 | - * @param string $sortBy |
|
192 | - * @param boolean $desc |
|
193 | - * @param array $columns |
|
194 | - * @return collection |
|
195 | - */ |
|
196 | - public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
197 | - { |
|
198 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
199 | - $sort = $desc ? 'desc' : 'asc'; |
|
200 | - return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
201 | - } |
|
168 | + /** |
|
169 | + * Fetch all records with relations from storage in pages. |
|
170 | + * |
|
171 | + * @param integer $perPage |
|
172 | + * @param array $relations |
|
173 | + * @param string $sortBy |
|
174 | + * @param boolean $desc |
|
175 | + * @param array $columns |
|
176 | + * @return collection |
|
177 | + */ |
|
178 | + public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
179 | + { |
|
180 | + $sort = $desc ? 'desc' : 'asc'; |
|
181 | + return $this->model->with($relations)->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Fetch all records with relations based on |
|
186 | + * the given condition from storage in pages. |
|
187 | + * |
|
188 | + * @param array $conditions array of conditions |
|
189 | + * @param integer $perPage |
|
190 | + * @param array $relations |
|
191 | + * @param string $sortBy |
|
192 | + * @param boolean $desc |
|
193 | + * @param array $columns |
|
194 | + * @return collection |
|
195 | + */ |
|
196 | + public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
197 | + { |
|
198 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
199 | + $sort = $desc ? 'desc' : 'asc'; |
|
200 | + return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * Save the given model to the storage. |
|
205 | - * |
|
206 | - * @param array $data |
|
207 | - * @return mixed |
|
208 | - */ |
|
209 | - public function save(array $data) |
|
210 | - { |
|
211 | - \Session::put('locale', 'all'); |
|
212 | - $model = false; |
|
213 | - $relations = []; |
|
214 | - |
|
215 | - \DB::transaction(function () use (&$model, $relations, $data) { |
|
203 | + /** |
|
204 | + * Save the given model to the storage. |
|
205 | + * |
|
206 | + * @param array $data |
|
207 | + * @return mixed |
|
208 | + */ |
|
209 | + public function save(array $data) |
|
210 | + { |
|
211 | + \Session::put('locale', 'all'); |
|
212 | + $model = false; |
|
213 | + $relations = []; |
|
214 | + |
|
215 | + \DB::transaction(function () use (&$model, $relations, $data) { |
|
216 | 216 | |
217 | - $model = $this->prepareModel($data); |
|
218 | - $relations = $this->prepareRelations($data, $model); |
|
219 | - $model = $this->saveModel($model, $relations); |
|
220 | - }); |
|
217 | + $model = $this->prepareModel($data); |
|
218 | + $relations = $this->prepareRelations($data, $model); |
|
219 | + $model = $this->saveModel($model, $relations); |
|
220 | + }); |
|
221 | 221 | |
222 | - return $model; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Delete record from the storage based on the given |
|
227 | - * condition. |
|
228 | - * |
|
229 | - * @param var $value condition value |
|
230 | - * @param string $attribute condition column name |
|
231 | - * @return void |
|
232 | - */ |
|
233 | - public function delete($value, $attribute = 'id') |
|
234 | - { |
|
235 | - if ($attribute == 'id') { |
|
236 | - \DB::transaction(function () use ($value) { |
|
237 | - $model = $this->model->lockForUpdate()->find($value); |
|
238 | - if (! $model) { |
|
239 | - \Errors::notFound(class_basename($this->model).' with id : '.$value); |
|
240 | - } |
|
222 | + return $model; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Delete record from the storage based on the given |
|
227 | + * condition. |
|
228 | + * |
|
229 | + * @param var $value condition value |
|
230 | + * @param string $attribute condition column name |
|
231 | + * @return void |
|
232 | + */ |
|
233 | + public function delete($value, $attribute = 'id') |
|
234 | + { |
|
235 | + if ($attribute == 'id') { |
|
236 | + \DB::transaction(function () use ($value) { |
|
237 | + $model = $this->model->lockForUpdate()->find($value); |
|
238 | + if (! $model) { |
|
239 | + \Errors::notFound(class_basename($this->model).' with id : '.$value); |
|
240 | + } |
|
241 | 241 | |
242 | - $model->delete(); |
|
243 | - }); |
|
244 | - } else { |
|
245 | - \DB::transaction(function () use ($value, $attribute) { |
|
246 | - $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) { |
|
247 | - $model->delete(); |
|
248 | - }); |
|
249 | - }); |
|
250 | - } |
|
251 | - } |
|
242 | + $model->delete(); |
|
243 | + }); |
|
244 | + } else { |
|
245 | + \DB::transaction(function () use ($value, $attribute) { |
|
246 | + $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) { |
|
247 | + $model->delete(); |
|
248 | + }); |
|
249 | + }); |
|
250 | + } |
|
251 | + } |
|
252 | 252 | |
253 | - /** |
|
254 | - * Fetch records from the storage based on the given |
|
255 | - * id. |
|
256 | - * |
|
257 | - * @param integer $id |
|
258 | - * @param string[] $relations |
|
259 | - * @param array $columns |
|
260 | - * @return object |
|
261 | - */ |
|
262 | - public function find($id, $relations = [], $columns = ['*']) |
|
263 | - { |
|
264 | - return $this->model->with($relations)->find($id, $columns); |
|
265 | - } |
|
253 | + /** |
|
254 | + * Fetch records from the storage based on the given |
|
255 | + * id. |
|
256 | + * |
|
257 | + * @param integer $id |
|
258 | + * @param string[] $relations |
|
259 | + * @param array $columns |
|
260 | + * @return object |
|
261 | + */ |
|
262 | + public function find($id, $relations = [], $columns = ['*']) |
|
263 | + { |
|
264 | + return $this->model->with($relations)->find($id, $columns); |
|
265 | + } |
|
266 | 266 | |
267 | - /** |
|
268 | - * Fetch records from the storage based on the given |
|
269 | - * condition. |
|
270 | - * |
|
271 | - * @param array $conditions array of conditions |
|
272 | - * @param array $relations |
|
273 | - * @param string $sortBy |
|
274 | - * @param boolean $desc |
|
275 | - * @param array $columns |
|
276 | - * @return collection |
|
277 | - */ |
|
278 | - public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
279 | - { |
|
280 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
281 | - $sort = $desc ? 'desc' : 'asc'; |
|
282 | - return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Fetch the first record from the storage based on the given |
|
287 | - * condition. |
|
288 | - * |
|
289 | - * @param array $conditions array of conditions |
|
290 | - * @param array $relations |
|
291 | - * @param array $columns |
|
292 | - * @return object |
|
293 | - */ |
|
294 | - public function first($conditions, $relations = [], $columns = ['*']) |
|
295 | - { |
|
296 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
297 | - return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns); |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Return the deleted models in pages based on the given conditions. |
|
302 | - * |
|
303 | - * @param array $conditions array of conditions |
|
304 | - * @param integer $perPage |
|
305 | - * @param string $sortBy |
|
306 | - * @param boolean $desc |
|
307 | - * @param array $columns |
|
308 | - * @return collection |
|
309 | - */ |
|
310 | - public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
311 | - { |
|
312 | - unset($conditions['page']); |
|
313 | - unset($conditions['perPage']); |
|
314 | - unset($conditions['sortBy']); |
|
315 | - unset($conditions['sort']); |
|
316 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
317 | - $sort = $desc ? 'desc' : 'asc'; |
|
318 | - $model = $this->model->onlyTrashed(); |
|
319 | - |
|
320 | - if (count($conditions['conditionValues'])) { |
|
321 | - $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
322 | - } |
|
323 | - |
|
324 | - return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Restore the deleted model. |
|
329 | - * |
|
330 | - * @param integer $id |
|
331 | - * @return void |
|
332 | - */ |
|
333 | - public function restore($id) |
|
334 | - { |
|
335 | - $model = $this->model->onlyTrashed()->find($id); |
|
336 | - |
|
337 | - if (! $model) { |
|
338 | - \Errors::notFound(class_basename($this->model).' with id : '.$id); |
|
339 | - } |
|
340 | - |
|
341 | - $model->restore(); |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Fill the model with the given data. |
|
346 | - * |
|
347 | - * @param array $data |
|
348 | - * |
|
349 | - * @return object |
|
350 | - */ |
|
351 | - public function prepareModel($data) |
|
352 | - { |
|
353 | - $modelClass = $this->model; |
|
354 | - |
|
355 | - /** |
|
356 | - * If the id is present in the data then select the model for updating, |
|
357 | - * else create new model. |
|
358 | - * @var array |
|
359 | - */ |
|
360 | - $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
|
361 | - if (! $model) { |
|
362 | - \Errors::notFound(class_basename($modelClass).' with id : '.$data['id']); |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Construct the model object with the given data, |
|
367 | - * and if there is a relation add it to relations array, |
|
368 | - * then save the model. |
|
369 | - */ |
|
370 | - foreach ($data as $key => $value) { |
|
371 | - if (array_search($key, $model->getFillable(), true) !== false) { |
|
372 | - /** |
|
373 | - * If the attribute isn't a relation and prevent attributes not in the fillable. |
|
374 | - */ |
|
375 | - $model->$key = $value; |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - return $model; |
|
380 | - } |
|
267 | + /** |
|
268 | + * Fetch records from the storage based on the given |
|
269 | + * condition. |
|
270 | + * |
|
271 | + * @param array $conditions array of conditions |
|
272 | + * @param array $relations |
|
273 | + * @param string $sortBy |
|
274 | + * @param boolean $desc |
|
275 | + * @param array $columns |
|
276 | + * @return collection |
|
277 | + */ |
|
278 | + public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
279 | + { |
|
280 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
281 | + $sort = $desc ? 'desc' : 'asc'; |
|
282 | + return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Fetch the first record from the storage based on the given |
|
287 | + * condition. |
|
288 | + * |
|
289 | + * @param array $conditions array of conditions |
|
290 | + * @param array $relations |
|
291 | + * @param array $columns |
|
292 | + * @return object |
|
293 | + */ |
|
294 | + public function first($conditions, $relations = [], $columns = ['*']) |
|
295 | + { |
|
296 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
297 | + return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns); |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Return the deleted models in pages based on the given conditions. |
|
302 | + * |
|
303 | + * @param array $conditions array of conditions |
|
304 | + * @param integer $perPage |
|
305 | + * @param string $sortBy |
|
306 | + * @param boolean $desc |
|
307 | + * @param array $columns |
|
308 | + * @return collection |
|
309 | + */ |
|
310 | + public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
311 | + { |
|
312 | + unset($conditions['page']); |
|
313 | + unset($conditions['perPage']); |
|
314 | + unset($conditions['sortBy']); |
|
315 | + unset($conditions['sort']); |
|
316 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
317 | + $sort = $desc ? 'desc' : 'asc'; |
|
318 | + $model = $this->model->onlyTrashed(); |
|
319 | + |
|
320 | + if (count($conditions['conditionValues'])) { |
|
321 | + $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
322 | + } |
|
323 | + |
|
324 | + return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Restore the deleted model. |
|
329 | + * |
|
330 | + * @param integer $id |
|
331 | + * @return void |
|
332 | + */ |
|
333 | + public function restore($id) |
|
334 | + { |
|
335 | + $model = $this->model->onlyTrashed()->find($id); |
|
336 | + |
|
337 | + if (! $model) { |
|
338 | + \Errors::notFound(class_basename($this->model).' with id : '.$id); |
|
339 | + } |
|
340 | + |
|
341 | + $model->restore(); |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Fill the model with the given data. |
|
346 | + * |
|
347 | + * @param array $data |
|
348 | + * |
|
349 | + * @return object |
|
350 | + */ |
|
351 | + public function prepareModel($data) |
|
352 | + { |
|
353 | + $modelClass = $this->model; |
|
354 | + |
|
355 | + /** |
|
356 | + * If the id is present in the data then select the model for updating, |
|
357 | + * else create new model. |
|
358 | + * @var array |
|
359 | + */ |
|
360 | + $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
|
361 | + if (! $model) { |
|
362 | + \Errors::notFound(class_basename($modelClass).' with id : '.$data['id']); |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Construct the model object with the given data, |
|
367 | + * and if there is a relation add it to relations array, |
|
368 | + * then save the model. |
|
369 | + */ |
|
370 | + foreach ($data as $key => $value) { |
|
371 | + if (array_search($key, $model->getFillable(), true) !== false) { |
|
372 | + /** |
|
373 | + * If the attribute isn't a relation and prevent attributes not in the fillable. |
|
374 | + */ |
|
375 | + $model->$key = $value; |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + return $model; |
|
380 | + } |
|
381 | 381 | |
382 | - /** |
|
383 | - * Prepare related models based on the given data for the given model. |
|
384 | - * |
|
385 | - * @param array $data |
|
386 | - * @param object $model |
|
387 | - * |
|
388 | - * @return array |
|
389 | - */ |
|
390 | - public function prepareRelations($data, $model) |
|
391 | - { |
|
392 | - /** |
|
393 | - * Construct the model object with the given data, |
|
394 | - * and if there is a relation add it to relations array, |
|
395 | - * then save the model. |
|
396 | - */ |
|
397 | - foreach ($data as $key => $value) { |
|
398 | - /** |
|
399 | - * If the attribute is a relation. |
|
400 | - */ |
|
401 | - $relation = \Str::camel($key); |
|
402 | - if (method_exists($model, $relation) && \Core::$relation()) { |
|
403 | - /** |
|
404 | - * Check if the relation is a collection. |
|
405 | - */ |
|
406 | - if (class_basename($model->$relation) == 'Collection') { |
|
407 | - /** |
|
408 | - * If the relation has no value then marke the relation data |
|
409 | - * related to the model to be deleted. |
|
410 | - */ |
|
411 | - if (! $value || ! count($value)) { |
|
412 | - $relations[$relation] = 'delete'; |
|
413 | - } |
|
414 | - } |
|
415 | - if (is_array($value)) { |
|
416 | - /** |
|
417 | - * Loop through the relation data. |
|
418 | - */ |
|
419 | - foreach ($value as $attr => $val) { |
|
420 | - /** |
|
421 | - * Get the relation model. |
|
422 | - */ |
|
423 | - $relationBaseModel = \Core::$relation()->model; |
|
424 | - |
|
425 | - /** |
|
426 | - * Check if the relation is a collection. |
|
427 | - */ |
|
428 | - if (class_basename($model->$relation) == 'Collection') { |
|
429 | - /** |
|
430 | - * If the id is present in the data then select the relation model for updating, |
|
431 | - * else create new model. |
|
432 | - */ |
|
433 | - $relationModel = Arr::has($val, 'id') ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel; |
|
434 | - |
|
435 | - /** |
|
436 | - * If model doesn't exists. |
|
437 | - */ |
|
438 | - if (! $relationModel) { |
|
439 | - \Errors::notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Loop through the relation attributes. |
|
444 | - */ |
|
445 | - foreach ($val as $attr => $val) { |
|
446 | - /** |
|
447 | - * Prevent the sub relations or attributes not in the fillable. |
|
448 | - */ |
|
449 | - if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) { |
|
450 | - $relationModel->$attr = $val; |
|
451 | - } |
|
452 | - } |
|
453 | - |
|
454 | - $relations[$relation][] = $relationModel; |
|
455 | - } else { |
|
456 | - /** |
|
457 | - * Prevent the sub relations. |
|
458 | - */ |
|
459 | - if (gettype($val) !== 'object' && gettype($val) !== 'array') { |
|
460 | - /** |
|
461 | - * If the id is present in the data then select the relation model for updating, |
|
462 | - * else create new model. |
|
463 | - */ |
|
464 | - $relationModel = Arr::has($value, 'id') ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel; |
|
465 | - |
|
466 | - /** |
|
467 | - * If model doesn't exists. |
|
468 | - */ |
|
469 | - if (! $relationModel) { |
|
470 | - \Errors::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
|
471 | - } |
|
472 | - |
|
473 | - foreach ($value as $relationAttribute => $relationValue) { |
|
474 | - /** |
|
475 | - * Prevent attributes not in the fillable. |
|
476 | - */ |
|
477 | - if (array_search($relationAttribute, $relationModel->getFillable(), true) !== false) { |
|
478 | - $relationModel->$relationAttribute = $relationValue; |
|
479 | - } |
|
480 | - } |
|
481 | - |
|
482 | - $relations[$relation] = $relationModel; |
|
483 | - } |
|
484 | - } |
|
485 | - } |
|
486 | - } |
|
487 | - } |
|
488 | - } |
|
489 | - |
|
490 | - return $relations; |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Save the model with related models. |
|
495 | - * |
|
496 | - * @param object $model |
|
497 | - * @param array $relations |
|
498 | - * |
|
499 | - * @return object |
|
500 | - */ |
|
501 | - public function saveModel($model, $relations) |
|
502 | - { |
|
503 | - |
|
504 | - /** |
|
505 | - * Loop through the relations array. |
|
506 | - */ |
|
507 | - foreach ($relations as $key => $value) { |
|
508 | - /** |
|
509 | - * If the relation is marked for delete then delete it. |
|
510 | - */ |
|
511 | - if ($value == 'delete' && $model->$key()->count()) { |
|
512 | - $model->$key()->delete(); |
|
513 | - } elseif (gettype($value) == 'array') { |
|
514 | - /** |
|
515 | - * Save the model. |
|
516 | - */ |
|
517 | - $model->save(); |
|
518 | - $ids = []; |
|
519 | - |
|
520 | - /** |
|
521 | - * Loop through the relations. |
|
522 | - */ |
|
523 | - foreach ($value as $val) { |
|
524 | - switch (class_basename($model->$key())) { |
|
525 | - /** |
|
526 | - * If the relation is one to many then update it's foreign key with |
|
527 | - * the model id and save it then add its id to ids array to delete all |
|
528 | - * relations who's id isn't in the ids array. |
|
529 | - */ |
|
530 | - case 'HasMany': |
|
531 | - $foreignKeyName = $model->$key()->getForeignKeyName(); |
|
532 | - $val->$foreignKeyName = $model->id; |
|
533 | - $val->save(); |
|
534 | - $ids[] = $val->id; |
|
535 | - break; |
|
536 | - |
|
537 | - /** |
|
538 | - * If the relation is many to many then add it's id to the ids array to |
|
539 | - * attache these ids to the model. |
|
540 | - */ |
|
541 | - case 'BelongsToMany': |
|
542 | - $val->save(); |
|
543 | - $ids[] = $val->id; |
|
544 | - break; |
|
545 | - } |
|
546 | - } |
|
547 | - switch (class_basename($model->$key())) { |
|
548 | - /** |
|
549 | - * If the relation is one to many then delete all |
|
550 | - * relations who's id isn't in the ids array. |
|
551 | - */ |
|
552 | - case 'HasMany': |
|
553 | - $model->$key()->whereNotIn('id', $ids)->delete(); |
|
554 | - break; |
|
555 | - |
|
556 | - /** |
|
557 | - * If the relation is many to many then |
|
558 | - * detach the previous data and attach |
|
559 | - * the ids array to the model. |
|
560 | - */ |
|
561 | - case 'BelongsToMany': |
|
562 | - $model->$key()->detach(); |
|
563 | - $model->$key()->attach($ids); |
|
564 | - break; |
|
565 | - } |
|
566 | - } else { |
|
567 | - switch (class_basename($model->$key())) { |
|
568 | - /** |
|
569 | - * If the relation is one to one. |
|
570 | - */ |
|
571 | - case 'HasOne': |
|
572 | - /** |
|
573 | - * Save the model. |
|
574 | - */ |
|
575 | - $model->save(); |
|
576 | - $foreignKeyName = $model->$key()->getForeignKeyName(); |
|
577 | - $value->$foreignKeyName = $model->id; |
|
578 | - $value->save(); |
|
579 | - break; |
|
580 | - case 'BelongsTo': |
|
581 | - /** |
|
582 | - * Save the model. |
|
583 | - */ |
|
584 | - $value->save(); |
|
585 | - $model->$key()->associate($value); |
|
586 | - break; |
|
587 | - } |
|
588 | - } |
|
589 | - } |
|
590 | - |
|
591 | - /** |
|
592 | - * Save the model. |
|
593 | - */ |
|
594 | - $model->save(); |
|
595 | - |
|
596 | - return $model; |
|
597 | - } |
|
598 | - |
|
599 | - /** |
|
600 | - * Build the conditions recursively for the retrieving methods. |
|
601 | - * @param array $conditions |
|
602 | - * @return array |
|
603 | - */ |
|
604 | - protected function constructConditions($conditions, $model) |
|
605 | - { |
|
606 | - $conditionString = ''; |
|
607 | - $conditionValues = []; |
|
608 | - foreach ($conditions as $key => $value) { |
|
609 | - if (Str::contains($key, '->')) { |
|
610 | - $key = $this->wrapJsonSelector($key); |
|
611 | - } |
|
612 | - |
|
613 | - if ($key == 'and') { |
|
614 | - $conditions = $this->constructConditions($value, $model); |
|
615 | - $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} '; |
|
616 | - $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
617 | - } elseif ($key == 'or') { |
|
618 | - $conditions = $this->constructConditions($value, $model); |
|
619 | - $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} '; |
|
620 | - $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
621 | - } else { |
|
622 | - if (is_array($value)) { |
|
623 | - $operator = $value['op']; |
|
624 | - if (strtolower($operator) == 'between') { |
|
625 | - $value1 = $value['val1']; |
|
626 | - $value2 = $value['val2']; |
|
627 | - } else { |
|
628 | - $value = Arr::get($value, 'val', ''); |
|
629 | - } |
|
630 | - } else { |
|
631 | - $operator = '='; |
|
632 | - } |
|
382 | + /** |
|
383 | + * Prepare related models based on the given data for the given model. |
|
384 | + * |
|
385 | + * @param array $data |
|
386 | + * @param object $model |
|
387 | + * |
|
388 | + * @return array |
|
389 | + */ |
|
390 | + public function prepareRelations($data, $model) |
|
391 | + { |
|
392 | + /** |
|
393 | + * Construct the model object with the given data, |
|
394 | + * and if there is a relation add it to relations array, |
|
395 | + * then save the model. |
|
396 | + */ |
|
397 | + foreach ($data as $key => $value) { |
|
398 | + /** |
|
399 | + * If the attribute is a relation. |
|
400 | + */ |
|
401 | + $relation = \Str::camel($key); |
|
402 | + if (method_exists($model, $relation) && \Core::$relation()) { |
|
403 | + /** |
|
404 | + * Check if the relation is a collection. |
|
405 | + */ |
|
406 | + if (class_basename($model->$relation) == 'Collection') { |
|
407 | + /** |
|
408 | + * If the relation has no value then marke the relation data |
|
409 | + * related to the model to be deleted. |
|
410 | + */ |
|
411 | + if (! $value || ! count($value)) { |
|
412 | + $relations[$relation] = 'delete'; |
|
413 | + } |
|
414 | + } |
|
415 | + if (is_array($value)) { |
|
416 | + /** |
|
417 | + * Loop through the relation data. |
|
418 | + */ |
|
419 | + foreach ($value as $attr => $val) { |
|
420 | + /** |
|
421 | + * Get the relation model. |
|
422 | + */ |
|
423 | + $relationBaseModel = \Core::$relation()->model; |
|
424 | + |
|
425 | + /** |
|
426 | + * Check if the relation is a collection. |
|
427 | + */ |
|
428 | + if (class_basename($model->$relation) == 'Collection') { |
|
429 | + /** |
|
430 | + * If the id is present in the data then select the relation model for updating, |
|
431 | + * else create new model. |
|
432 | + */ |
|
433 | + $relationModel = Arr::has($val, 'id') ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel; |
|
434 | + |
|
435 | + /** |
|
436 | + * If model doesn't exists. |
|
437 | + */ |
|
438 | + if (! $relationModel) { |
|
439 | + \Errors::notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Loop through the relation attributes. |
|
444 | + */ |
|
445 | + foreach ($val as $attr => $val) { |
|
446 | + /** |
|
447 | + * Prevent the sub relations or attributes not in the fillable. |
|
448 | + */ |
|
449 | + if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) { |
|
450 | + $relationModel->$attr = $val; |
|
451 | + } |
|
452 | + } |
|
453 | + |
|
454 | + $relations[$relation][] = $relationModel; |
|
455 | + } else { |
|
456 | + /** |
|
457 | + * Prevent the sub relations. |
|
458 | + */ |
|
459 | + if (gettype($val) !== 'object' && gettype($val) !== 'array') { |
|
460 | + /** |
|
461 | + * If the id is present in the data then select the relation model for updating, |
|
462 | + * else create new model. |
|
463 | + */ |
|
464 | + $relationModel = Arr::has($value, 'id') ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel; |
|
465 | + |
|
466 | + /** |
|
467 | + * If model doesn't exists. |
|
468 | + */ |
|
469 | + if (! $relationModel) { |
|
470 | + \Errors::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
|
471 | + } |
|
472 | + |
|
473 | + foreach ($value as $relationAttribute => $relationValue) { |
|
474 | + /** |
|
475 | + * Prevent attributes not in the fillable. |
|
476 | + */ |
|
477 | + if (array_search($relationAttribute, $relationModel->getFillable(), true) !== false) { |
|
478 | + $relationModel->$relationAttribute = $relationValue; |
|
479 | + } |
|
480 | + } |
|
481 | + |
|
482 | + $relations[$relation] = $relationModel; |
|
483 | + } |
|
484 | + } |
|
485 | + } |
|
486 | + } |
|
487 | + } |
|
488 | + } |
|
489 | + |
|
490 | + return $relations; |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Save the model with related models. |
|
495 | + * |
|
496 | + * @param object $model |
|
497 | + * @param array $relations |
|
498 | + * |
|
499 | + * @return object |
|
500 | + */ |
|
501 | + public function saveModel($model, $relations) |
|
502 | + { |
|
503 | + |
|
504 | + /** |
|
505 | + * Loop through the relations array. |
|
506 | + */ |
|
507 | + foreach ($relations as $key => $value) { |
|
508 | + /** |
|
509 | + * If the relation is marked for delete then delete it. |
|
510 | + */ |
|
511 | + if ($value == 'delete' && $model->$key()->count()) { |
|
512 | + $model->$key()->delete(); |
|
513 | + } elseif (gettype($value) == 'array') { |
|
514 | + /** |
|
515 | + * Save the model. |
|
516 | + */ |
|
517 | + $model->save(); |
|
518 | + $ids = []; |
|
519 | + |
|
520 | + /** |
|
521 | + * Loop through the relations. |
|
522 | + */ |
|
523 | + foreach ($value as $val) { |
|
524 | + switch (class_basename($model->$key())) { |
|
525 | + /** |
|
526 | + * If the relation is one to many then update it's foreign key with |
|
527 | + * the model id and save it then add its id to ids array to delete all |
|
528 | + * relations who's id isn't in the ids array. |
|
529 | + */ |
|
530 | + case 'HasMany': |
|
531 | + $foreignKeyName = $model->$key()->getForeignKeyName(); |
|
532 | + $val->$foreignKeyName = $model->id; |
|
533 | + $val->save(); |
|
534 | + $ids[] = $val->id; |
|
535 | + break; |
|
536 | + |
|
537 | + /** |
|
538 | + * If the relation is many to many then add it's id to the ids array to |
|
539 | + * attache these ids to the model. |
|
540 | + */ |
|
541 | + case 'BelongsToMany': |
|
542 | + $val->save(); |
|
543 | + $ids[] = $val->id; |
|
544 | + break; |
|
545 | + } |
|
546 | + } |
|
547 | + switch (class_basename($model->$key())) { |
|
548 | + /** |
|
549 | + * If the relation is one to many then delete all |
|
550 | + * relations who's id isn't in the ids array. |
|
551 | + */ |
|
552 | + case 'HasMany': |
|
553 | + $model->$key()->whereNotIn('id', $ids)->delete(); |
|
554 | + break; |
|
555 | + |
|
556 | + /** |
|
557 | + * If the relation is many to many then |
|
558 | + * detach the previous data and attach |
|
559 | + * the ids array to the model. |
|
560 | + */ |
|
561 | + case 'BelongsToMany': |
|
562 | + $model->$key()->detach(); |
|
563 | + $model->$key()->attach($ids); |
|
564 | + break; |
|
565 | + } |
|
566 | + } else { |
|
567 | + switch (class_basename($model->$key())) { |
|
568 | + /** |
|
569 | + * If the relation is one to one. |
|
570 | + */ |
|
571 | + case 'HasOne': |
|
572 | + /** |
|
573 | + * Save the model. |
|
574 | + */ |
|
575 | + $model->save(); |
|
576 | + $foreignKeyName = $model->$key()->getForeignKeyName(); |
|
577 | + $value->$foreignKeyName = $model->id; |
|
578 | + $value->save(); |
|
579 | + break; |
|
580 | + case 'BelongsTo': |
|
581 | + /** |
|
582 | + * Save the model. |
|
583 | + */ |
|
584 | + $value->save(); |
|
585 | + $model->$key()->associate($value); |
|
586 | + break; |
|
587 | + } |
|
588 | + } |
|
589 | + } |
|
590 | + |
|
591 | + /** |
|
592 | + * Save the model. |
|
593 | + */ |
|
594 | + $model->save(); |
|
595 | + |
|
596 | + return $model; |
|
597 | + } |
|
598 | + |
|
599 | + /** |
|
600 | + * Build the conditions recursively for the retrieving methods. |
|
601 | + * @param array $conditions |
|
602 | + * @return array |
|
603 | + */ |
|
604 | + protected function constructConditions($conditions, $model) |
|
605 | + { |
|
606 | + $conditionString = ''; |
|
607 | + $conditionValues = []; |
|
608 | + foreach ($conditions as $key => $value) { |
|
609 | + if (Str::contains($key, '->')) { |
|
610 | + $key = $this->wrapJsonSelector($key); |
|
611 | + } |
|
612 | + |
|
613 | + if ($key == 'and') { |
|
614 | + $conditions = $this->constructConditions($value, $model); |
|
615 | + $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} '; |
|
616 | + $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
617 | + } elseif ($key == 'or') { |
|
618 | + $conditions = $this->constructConditions($value, $model); |
|
619 | + $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} '; |
|
620 | + $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
621 | + } else { |
|
622 | + if (is_array($value)) { |
|
623 | + $operator = $value['op']; |
|
624 | + if (strtolower($operator) == 'between') { |
|
625 | + $value1 = $value['val1']; |
|
626 | + $value2 = $value['val2']; |
|
627 | + } else { |
|
628 | + $value = Arr::get($value, 'val', ''); |
|
629 | + } |
|
630 | + } else { |
|
631 | + $operator = '='; |
|
632 | + } |
|
633 | 633 | |
634 | - if (strtolower($operator) == 'between') { |
|
635 | - $conditionString .= $key.' >= ? and '; |
|
636 | - $conditionValues[] = $value1; |
|
637 | - |
|
638 | - $conditionString .= $key.' <= ? {op} '; |
|
639 | - $conditionValues[] = $value2; |
|
640 | - } elseif (strtolower($operator) == 'in') { |
|
641 | - $conditionValues = array_merge($conditionValues, $value); |
|
642 | - $inBindingsString = rtrim(str_repeat('?,', count($value)), ','); |
|
643 | - $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} '; |
|
644 | - } elseif (strtolower($operator) == 'null') { |
|
645 | - $conditionString .= $key.' is null {op} '; |
|
646 | - } elseif (strtolower($operator) == 'not null') { |
|
647 | - $conditionString .= $key.' is not null {op} '; |
|
648 | - } elseif (strtolower($operator) == 'has') { |
|
649 | - $sql = $model->withTrashed()->has($key)->toSql(); |
|
650 | - $conditions = $this->constructConditions($value, $model->$key()->getRelated()); |
|
651 | - $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} '; |
|
652 | - $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
653 | - } else { |
|
654 | - $conditionString .= $key.' '.$operator.' ? {op} '; |
|
655 | - $conditionValues[] = $value; |
|
656 | - } |
|
657 | - } |
|
658 | - } |
|
659 | - $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
660 | - return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
|
661 | - } |
|
662 | - |
|
663 | - /** |
|
664 | - * Wrap the given JSON selector. |
|
665 | - * |
|
666 | - * @param string $value |
|
667 | - * @return string |
|
668 | - */ |
|
669 | - protected function wrapJsonSelector($value) |
|
670 | - { |
|
671 | - $removeLast = strpos($value, ')'); |
|
672 | - $value = $removeLast === false ? $value : substr($value, 0, $removeLast); |
|
673 | - $path = explode('->', $value); |
|
674 | - $field = array_shift($path); |
|
675 | - $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) { |
|
676 | - return '"'.$part.'"'; |
|
677 | - })->implode('.')); |
|
634 | + if (strtolower($operator) == 'between') { |
|
635 | + $conditionString .= $key.' >= ? and '; |
|
636 | + $conditionValues[] = $value1; |
|
637 | + |
|
638 | + $conditionString .= $key.' <= ? {op} '; |
|
639 | + $conditionValues[] = $value2; |
|
640 | + } elseif (strtolower($operator) == 'in') { |
|
641 | + $conditionValues = array_merge($conditionValues, $value); |
|
642 | + $inBindingsString = rtrim(str_repeat('?,', count($value)), ','); |
|
643 | + $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} '; |
|
644 | + } elseif (strtolower($operator) == 'null') { |
|
645 | + $conditionString .= $key.' is null {op} '; |
|
646 | + } elseif (strtolower($operator) == 'not null') { |
|
647 | + $conditionString .= $key.' is not null {op} '; |
|
648 | + } elseif (strtolower($operator) == 'has') { |
|
649 | + $sql = $model->withTrashed()->has($key)->toSql(); |
|
650 | + $conditions = $this->constructConditions($value, $model->$key()->getRelated()); |
|
651 | + $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} '; |
|
652 | + $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
653 | + } else { |
|
654 | + $conditionString .= $key.' '.$operator.' ? {op} '; |
|
655 | + $conditionValues[] = $value; |
|
656 | + } |
|
657 | + } |
|
658 | + } |
|
659 | + $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
660 | + return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
|
661 | + } |
|
662 | + |
|
663 | + /** |
|
664 | + * Wrap the given JSON selector. |
|
665 | + * |
|
666 | + * @param string $value |
|
667 | + * @return string |
|
668 | + */ |
|
669 | + protected function wrapJsonSelector($value) |
|
670 | + { |
|
671 | + $removeLast = strpos($value, ')'); |
|
672 | + $value = $removeLast === false ? $value : substr($value, 0, $removeLast); |
|
673 | + $path = explode('->', $value); |
|
674 | + $field = array_shift($path); |
|
675 | + $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) { |
|
676 | + return '"'.$part.'"'; |
|
677 | + })->implode('.')); |
|
678 | 678 | |
679 | - return $removeLast === false ? $result : $result.')'; |
|
680 | - } |
|
679 | + return $removeLast === false ? $result : $result.')'; |
|
680 | + } |
|
681 | 681 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function __construct($model) |
21 | 21 | { |
22 | - $this->model = $model; |
|
22 | + $this->model = $model; |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * Construct the select conditions for the model. |
84 | 84 | */ |
85 | - $model->where(function ($q) use ($query, $conditionColumns, $relations) { |
|
85 | + $model->where(function($q) use ($query, $conditionColumns, $relations) { |
|
86 | 86 | |
87 | 87 | if (count($conditionColumns)) { |
88 | 88 | $column = 'LOWER('.array_shift($conditionColumns).')'; |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | /** |
125 | 125 | * Construct the relation condition. |
126 | 126 | */ |
127 | - $q->orWhereHas($relation, function ($subModel) use ($query, $relation) { |
|
127 | + $q->orWhereHas($relation, function($subModel) use ($query, $relation) { |
|
128 | 128 | |
129 | - $subModel->where(function ($q) use ($query, $relation) { |
|
129 | + $subModel->where(function($q) use ($query, $relation) { |
|
130 | 130 | |
131 | 131 | /** |
132 | 132 | * Get columns of the relation. |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $model = false; |
213 | 213 | $relations = []; |
214 | 214 | |
215 | - \DB::transaction(function () use (&$model, $relations, $data) { |
|
215 | + \DB::transaction(function() use (&$model, $relations, $data) { |
|
216 | 216 | |
217 | 217 | $model = $this->prepareModel($data); |
218 | 218 | $relations = $this->prepareRelations($data, $model); |
@@ -233,17 +233,17 @@ discard block |
||
233 | 233 | public function delete($value, $attribute = 'id') |
234 | 234 | { |
235 | 235 | if ($attribute == 'id') { |
236 | - \DB::transaction(function () use ($value) { |
|
236 | + \DB::transaction(function() use ($value) { |
|
237 | 237 | $model = $this->model->lockForUpdate()->find($value); |
238 | - if (! $model) { |
|
238 | + if ( ! $model) { |
|
239 | 239 | \Errors::notFound(class_basename($this->model).' with id : '.$value); |
240 | 240 | } |
241 | 241 | |
242 | 242 | $model->delete(); |
243 | 243 | }); |
244 | 244 | } else { |
245 | - \DB::transaction(function () use ($value, $attribute) { |
|
246 | - $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) { |
|
245 | + \DB::transaction(function() use ($value, $attribute) { |
|
246 | + $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function($model) { |
|
247 | 247 | $model->delete(); |
248 | 248 | }); |
249 | 249 | }); |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | { |
335 | 335 | $model = $this->model->onlyTrashed()->find($id); |
336 | 336 | |
337 | - if (! $model) { |
|
337 | + if ( ! $model) { |
|
338 | 338 | \Errors::notFound(class_basename($this->model).' with id : '.$id); |
339 | 339 | } |
340 | 340 | |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | * @var array |
359 | 359 | */ |
360 | 360 | $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
361 | - if (! $model) { |
|
361 | + if ( ! $model) { |
|
362 | 362 | \Errors::notFound(class_basename($modelClass).' with id : '.$data['id']); |
363 | 363 | } |
364 | 364 | |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | * If the relation has no value then marke the relation data |
409 | 409 | * related to the model to be deleted. |
410 | 410 | */ |
411 | - if (! $value || ! count($value)) { |
|
411 | + if ( ! $value || ! count($value)) { |
|
412 | 412 | $relations[$relation] = 'delete'; |
413 | 413 | } |
414 | 414 | } |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | /** |
436 | 436 | * If model doesn't exists. |
437 | 437 | */ |
438 | - if (! $relationModel) { |
|
438 | + if ( ! $relationModel) { |
|
439 | 439 | \Errors::notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
440 | 440 | } |
441 | 441 | |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | /** |
467 | 467 | * If model doesn't exists. |
468 | 468 | */ |
469 | - if (! $relationModel) { |
|
469 | + if ( ! $relationModel) { |
|
470 | 470 | \Errors::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
471 | 471 | } |
472 | 472 | |
@@ -672,7 +672,7 @@ discard block |
||
672 | 672 | $value = $removeLast === false ? $value : substr($value, 0, $removeLast); |
673 | 673 | $path = explode('->', $value); |
674 | 674 | $field = array_shift($path); |
675 | - $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) { |
|
675 | + $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function($part) { |
|
676 | 676 | return '"'.$part.'"'; |
677 | 677 | })->implode('.')); |
678 | 678 |
@@ -9,41 +9,41 @@ |
||
9 | 9 | |
10 | 10 | class ConfirmEmail extends Notification implements ShouldQueue |
11 | 11 | { |
12 | - use Queueable; |
|
12 | + use Queueable; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Init new object. |
|
16 | - * |
|
17 | - * @return void |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - // |
|
22 | - } |
|
14 | + /** |
|
15 | + * Init new object. |
|
16 | + * |
|
17 | + * @return void |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + // |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * Get the notification's delivery channels. |
|
26 | - * |
|
27 | - * @param mixed $notifiable |
|
28 | - * @return string[] |
|
29 | - */ |
|
30 | - public function via($notifiable) |
|
31 | - { |
|
32 | - return ['mail']; |
|
33 | - } |
|
24 | + /** |
|
25 | + * Get the notification's delivery channels. |
|
26 | + * |
|
27 | + * @param mixed $notifiable |
|
28 | + * @return string[] |
|
29 | + */ |
|
30 | + public function via($notifiable) |
|
31 | + { |
|
32 | + return ['mail']; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Get the mail representation of the notification. |
|
37 | - * |
|
38 | - * @param mixed $notifiable |
|
39 | - * @return \Illuminate\Notifications\Messages\MailMessage |
|
40 | - */ |
|
41 | - public function toMail($notifiable) |
|
42 | - { |
|
43 | - return (new MailMessage) |
|
44 | - ->subject('Email verification') |
|
45 | - ->line('Email verification') |
|
46 | - ->line('To validate your email click on the button below') |
|
47 | - ->action('Verify your email', config('skeleton.confrim_email_url').'/'.$notifiable->confirmation_code); |
|
48 | - } |
|
35 | + /** |
|
36 | + * Get the mail representation of the notification. |
|
37 | + * |
|
38 | + * @param mixed $notifiable |
|
39 | + * @return \Illuminate\Notifications\Messages\MailMessage |
|
40 | + */ |
|
41 | + public function toMail($notifiable) |
|
42 | + { |
|
43 | + return (new MailMessage) |
|
44 | + ->subject('Email verification') |
|
45 | + ->line('Email verification') |
|
46 | + ->line('To validate your email click on the button below') |
|
47 | + ->action('Verify your email', config('skeleton.confrim_email_url').'/'.$notifiable->confirmation_code); |
|
48 | + } |
|
49 | 49 | } |