@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @param array $relations |
34 | 34 | * @param string $sortBy |
35 | - * @param boolean $desc |
|
35 | + * @param integer $desc |
|
36 | 36 | * @param array $columns |
37 | 37 | * @return collection |
38 | 38 | */ |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @param integer $perPage |
51 | 51 | * @param array $relations |
52 | 52 | * @param string $sortBy |
53 | - * @param boolean $desc |
|
53 | + * @param integer $desc |
|
54 | 54 | * @param array $columns |
55 | 55 | * @return collection |
56 | 56 | */ |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @param integer $perPage |
134 | 134 | * @param array $relations |
135 | 135 | * @param string $sortBy |
136 | - * @param boolean $desc |
|
136 | + * @param integer $desc |
|
137 | 137 | * @param array $columns |
138 | 138 | * @return collection |
139 | 139 | */ |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @param integer $perPage |
152 | 152 | * @param array $relations |
153 | 153 | * @param string $sortBy |
154 | - * @param boolean $desc |
|
154 | + * @param integer $desc |
|
155 | 155 | * @param array $columns |
156 | 156 | * @return collection |
157 | 157 | */ |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | * @param array $conditions array of conditions |
469 | 469 | * @param array $relations |
470 | 470 | * @param string $sortBy |
471 | - * @param boolean $desc |
|
471 | + * @param integer $desc |
|
472 | 472 | * @param array $columns |
473 | 473 | * @return collection |
474 | 474 | */ |
@@ -435,8 +435,7 @@ discard block |
||
435 | 435 | $model->delete(); |
436 | 436 | $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false; |
437 | 437 | }); |
438 | - } |
|
439 | - else |
|
438 | + } else |
|
440 | 439 | { |
441 | 440 | \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
442 | 441 | call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){ |
@@ -509,13 +508,11 @@ discard block |
||
509 | 508 | { |
510 | 509 | $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} '; |
511 | 510 | $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
512 | - } |
|
513 | - else if ($key == 'or') |
|
511 | + } else if ($key == 'or') |
|
514 | 512 | { |
515 | 513 | $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} '; |
516 | 514 | $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
517 | - } |
|
518 | - else |
|
515 | + } else |
|
519 | 516 | { |
520 | 517 | $conditionString .= $key . '=? {op} '; |
521 | 518 | $conditionValues[] = $value; |
@@ -4,533 +4,533 @@ |
||
4 | 4 | |
5 | 5 | abstract class AbstractRepository implements RepositoryInterface |
6 | 6 | { |
7 | - /** |
|
8 | - * The model implementation. |
|
9 | - * |
|
10 | - * @var model |
|
11 | - */ |
|
12 | - public $model; |
|
7 | + /** |
|
8 | + * The model implementation. |
|
9 | + * |
|
10 | + * @var model |
|
11 | + */ |
|
12 | + public $model; |
|
13 | 13 | |
14 | - /** |
|
15 | - * The config implementation. |
|
16 | - * |
|
17 | - * @var config |
|
18 | - */ |
|
19 | - protected $config; |
|
14 | + /** |
|
15 | + * The config implementation. |
|
16 | + * |
|
17 | + * @var config |
|
18 | + */ |
|
19 | + protected $config; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Create new AbstractRepository instance. |
|
23 | - */ |
|
24 | - public function __construct() |
|
25 | - { |
|
26 | - $this->config = \CoreConfig::getConfig(); |
|
27 | - $this->model = \App::make($this->getModel()); |
|
28 | - } |
|
21 | + /** |
|
22 | + * Create new AbstractRepository instance. |
|
23 | + */ |
|
24 | + public function __construct() |
|
25 | + { |
|
26 | + $this->config = \CoreConfig::getConfig(); |
|
27 | + $this->model = \App::make($this->getModel()); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Fetch all records with relations from the storage. |
|
32 | - * |
|
33 | - * @param array $relations |
|
34 | - * @param string $sortBy |
|
35 | - * @param boolean $desc |
|
36 | - * @param array $columns |
|
37 | - * @return collection |
|
38 | - */ |
|
39 | - public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
40 | - { |
|
41 | - $sort = $desc ? 'desc' : 'asc'; |
|
42 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->get($columns); |
|
43 | - } |
|
30 | + /** |
|
31 | + * Fetch all records with relations from the storage. |
|
32 | + * |
|
33 | + * @param array $relations |
|
34 | + * @param string $sortBy |
|
35 | + * @param boolean $desc |
|
36 | + * @param array $columns |
|
37 | + * @return collection |
|
38 | + */ |
|
39 | + public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
40 | + { |
|
41 | + $sort = $desc ? 'desc' : 'asc'; |
|
42 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->get($columns); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Fetch all records with relations from storage in pages |
|
47 | - * that matche the given query. |
|
48 | - * |
|
49 | - * @param string $query |
|
50 | - * @param integer $perPage |
|
51 | - * @param array $relations |
|
52 | - * @param string $sortBy |
|
53 | - * @param boolean $desc |
|
54 | - * @param array $columns |
|
55 | - * @return collection |
|
56 | - */ |
|
57 | - public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
58 | - { |
|
59 | - $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
60 | - $conditionColumns = $this->model->getFillable(); |
|
61 | - $sort = $desc ? 'desc' : 'asc'; |
|
45 | + /** |
|
46 | + * Fetch all records with relations from storage in pages |
|
47 | + * that matche the given query. |
|
48 | + * |
|
49 | + * @param string $query |
|
50 | + * @param integer $perPage |
|
51 | + * @param array $relations |
|
52 | + * @param string $sortBy |
|
53 | + * @param boolean $desc |
|
54 | + * @param array $columns |
|
55 | + * @return collection |
|
56 | + */ |
|
57 | + public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
58 | + { |
|
59 | + $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
60 | + $conditionColumns = $this->model->getFillable(); |
|
61 | + $sort = $desc ? 'desc' : 'asc'; |
|
62 | 62 | |
63 | - /** |
|
64 | - * Construct the select conditions for the model. |
|
65 | - */ |
|
66 | - $model->where(function ($q) use ($query, $conditionColumns, $relations){ |
|
63 | + /** |
|
64 | + * Construct the select conditions for the model. |
|
65 | + */ |
|
66 | + $model->where(function ($q) use ($query, $conditionColumns, $relations){ |
|
67 | 67 | |
68 | - /** |
|
69 | - * Use the first element in the model columns to construct the first condition. |
|
70 | - */ |
|
71 | - $q->where(\DB::raw('LOWER(' . array_shift($conditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
68 | + /** |
|
69 | + * Use the first element in the model columns to construct the first condition. |
|
70 | + */ |
|
71 | + $q->where(\DB::raw('LOWER(' . array_shift($conditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
72 | 72 | |
73 | - /** |
|
74 | - * Loop through the rest of the columns to construct or where conditions. |
|
75 | - */ |
|
76 | - foreach ($conditionColumns as $column) |
|
77 | - { |
|
78 | - $q->orWhere(\DB::raw('LOWER(' . $column . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
79 | - } |
|
73 | + /** |
|
74 | + * Loop through the rest of the columns to construct or where conditions. |
|
75 | + */ |
|
76 | + foreach ($conditionColumns as $column) |
|
77 | + { |
|
78 | + $q->orWhere(\DB::raw('LOWER(' . $column . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Loop through the model relations. |
|
83 | - */ |
|
84 | - foreach ($relations as $relation) |
|
85 | - { |
|
86 | - /** |
|
87 | - * Remove the sub relation if exists. |
|
88 | - */ |
|
89 | - $relation = explode('.', $relation)[0]; |
|
81 | + /** |
|
82 | + * Loop through the model relations. |
|
83 | + */ |
|
84 | + foreach ($relations as $relation) |
|
85 | + { |
|
86 | + /** |
|
87 | + * Remove the sub relation if exists. |
|
88 | + */ |
|
89 | + $relation = explode('.', $relation)[0]; |
|
90 | 90 | |
91 | - /** |
|
92 | - * Try to fetch the relation repository from the core. |
|
93 | - */ |
|
94 | - if (\Core::$relation()) |
|
95 | - { |
|
96 | - /** |
|
97 | - * Construct the relation condition. |
|
98 | - */ |
|
99 | - $q->orWhereHas($relation, function ($subModel) use ($query, $relation){ |
|
91 | + /** |
|
92 | + * Try to fetch the relation repository from the core. |
|
93 | + */ |
|
94 | + if (\Core::$relation()) |
|
95 | + { |
|
96 | + /** |
|
97 | + * Construct the relation condition. |
|
98 | + */ |
|
99 | + $q->orWhereHas($relation, function ($subModel) use ($query, $relation){ |
|
100 | 100 | |
101 | - $subModel->where(function ($q) use ($query, $relation){ |
|
101 | + $subModel->where(function ($q) use ($query, $relation){ |
|
102 | 102 | |
103 | - /** |
|
104 | - * Get columns of the relation. |
|
105 | - */ |
|
106 | - $subConditionColumns = \Core::$relation()->model->getFillable(); |
|
103 | + /** |
|
104 | + * Get columns of the relation. |
|
105 | + */ |
|
106 | + $subConditionColumns = \Core::$relation()->model->getFillable(); |
|
107 | 107 | |
108 | - /** |
|
109 | - * Use the first element in the relation model columns to construct the first condition. |
|
110 | - */ |
|
111 | - $q->where(\DB::raw('LOWER(' . array_shift($subConditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
108 | + /** |
|
109 | + * Use the first element in the relation model columns to construct the first condition. |
|
110 | + */ |
|
111 | + $q->where(\DB::raw('LOWER(' . array_shift($subConditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
112 | 112 | |
113 | - /** |
|
114 | - * Loop through the rest of the columns to construct or where conditions. |
|
115 | - */ |
|
116 | - foreach ($subConditionColumns as $subConditionColumn) |
|
117 | - { |
|
118 | - $q->orWhere(\DB::raw('LOWER(' . $subConditionColumn . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
119 | - } |
|
120 | - }); |
|
113 | + /** |
|
114 | + * Loop through the rest of the columns to construct or where conditions. |
|
115 | + */ |
|
116 | + foreach ($subConditionColumns as $subConditionColumn) |
|
117 | + { |
|
118 | + $q->orWhere(\DB::raw('LOWER(' . $subConditionColumn . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
119 | + } |
|
120 | + }); |
|
121 | 121 | |
122 | - }); |
|
123 | - } |
|
124 | - } |
|
125 | - }); |
|
122 | + }); |
|
123 | + } |
|
124 | + } |
|
125 | + }); |
|
126 | 126 | |
127 | - return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
128 | - } |
|
127 | + return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Fetch all records with relations from storage in pages. |
|
132 | - * |
|
133 | - * @param integer $perPage |
|
134 | - * @param array $relations |
|
135 | - * @param string $sortBy |
|
136 | - * @param boolean $desc |
|
137 | - * @param array $columns |
|
138 | - * @return collection |
|
139 | - */ |
|
140 | - public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
141 | - { |
|
142 | - $sort = $desc ? 'desc' : 'asc'; |
|
143 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
144 | - } |
|
130 | + /** |
|
131 | + * Fetch all records with relations from storage in pages. |
|
132 | + * |
|
133 | + * @param integer $perPage |
|
134 | + * @param array $relations |
|
135 | + * @param string $sortBy |
|
136 | + * @param boolean $desc |
|
137 | + * @param array $columns |
|
138 | + * @return collection |
|
139 | + */ |
|
140 | + public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
141 | + { |
|
142 | + $sort = $desc ? 'desc' : 'asc'; |
|
143 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Fetch all records with relations based on |
|
148 | - * the given condition from storage in pages. |
|
149 | - * |
|
150 | - * @param array $conditions array of conditions |
|
151 | - * @param integer $perPage |
|
152 | - * @param array $relations |
|
153 | - * @param string $sortBy |
|
154 | - * @param boolean $desc |
|
155 | - * @param array $columns |
|
156 | - * @return collection |
|
157 | - */ |
|
158 | - public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
159 | - { |
|
160 | - unset($conditions['page']); |
|
161 | - $conditions = $this->constructConditions($conditions); |
|
162 | - $sort = $desc ? 'desc' : 'asc'; |
|
163 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
164 | - } |
|
146 | + /** |
|
147 | + * Fetch all records with relations based on |
|
148 | + * the given condition from storage in pages. |
|
149 | + * |
|
150 | + * @param array $conditions array of conditions |
|
151 | + * @param integer $perPage |
|
152 | + * @param array $relations |
|
153 | + * @param string $sortBy |
|
154 | + * @param boolean $desc |
|
155 | + * @param array $columns |
|
156 | + * @return collection |
|
157 | + */ |
|
158 | + public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
159 | + { |
|
160 | + unset($conditions['page']); |
|
161 | + $conditions = $this->constructConditions($conditions); |
|
162 | + $sort = $desc ? 'desc' : 'asc'; |
|
163 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * Save the given model to the storage. |
|
168 | - * |
|
169 | - * @param array $data |
|
170 | - * @param boolean $saveLog |
|
171 | - * @return object |
|
172 | - */ |
|
173 | - public function save(array $data, $saveLog = true) |
|
174 | - { |
|
175 | - $model = false; |
|
176 | - $modelClass = $this->model; |
|
177 | - $relations = []; |
|
178 | - $with = []; |
|
166 | + /** |
|
167 | + * Save the given model to the storage. |
|
168 | + * |
|
169 | + * @param array $data |
|
170 | + * @param boolean $saveLog |
|
171 | + * @return object |
|
172 | + */ |
|
173 | + public function save(array $data, $saveLog = true) |
|
174 | + { |
|
175 | + $model = false; |
|
176 | + $modelClass = $this->model; |
|
177 | + $relations = []; |
|
178 | + $with = []; |
|
179 | 179 | |
180 | - \DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) { |
|
181 | - /** |
|
182 | - * If the id is present in the data then select the model for updating, |
|
183 | - * else create new model. |
|
184 | - * @var array |
|
185 | - */ |
|
186 | - $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
|
187 | - if ( ! $model) |
|
188 | - { |
|
189 | - \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']); |
|
190 | - } |
|
180 | + \DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) { |
|
181 | + /** |
|
182 | + * If the id is present in the data then select the model for updating, |
|
183 | + * else create new model. |
|
184 | + * @var array |
|
185 | + */ |
|
186 | + $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
|
187 | + if ( ! $model) |
|
188 | + { |
|
189 | + \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']); |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * Construct the model object with the given data, |
|
194 | - * and if there is a relation add it to relations array, |
|
195 | - * then save the model. |
|
196 | - */ |
|
197 | - foreach ($data as $key => $value) |
|
198 | - { |
|
199 | - /** |
|
200 | - * If the attribute is a relation. |
|
201 | - */ |
|
202 | - $relation = camel_case($key); |
|
203 | - if (method_exists($model, $relation)) |
|
204 | - { |
|
205 | - /** |
|
206 | - * Add the relation to the with array to eager load the created model with the relations. |
|
207 | - */ |
|
208 | - $with[] = $relation; |
|
192 | + /** |
|
193 | + * Construct the model object with the given data, |
|
194 | + * and if there is a relation add it to relations array, |
|
195 | + * then save the model. |
|
196 | + */ |
|
197 | + foreach ($data as $key => $value) |
|
198 | + { |
|
199 | + /** |
|
200 | + * If the attribute is a relation. |
|
201 | + */ |
|
202 | + $relation = camel_case($key); |
|
203 | + if (method_exists($model, $relation)) |
|
204 | + { |
|
205 | + /** |
|
206 | + * Add the relation to the with array to eager load the created model with the relations. |
|
207 | + */ |
|
208 | + $with[] = $relation; |
|
209 | 209 | |
210 | - /** |
|
211 | - * Check if the relation is a collection. |
|
212 | - */ |
|
213 | - if (class_basename($model->$relation) == 'Collection') |
|
214 | - { |
|
215 | - /** |
|
216 | - * If the relation has no value then marke the relation data |
|
217 | - * related to the model to be deleted. |
|
218 | - */ |
|
219 | - if ( ! $value || ! count($value)) |
|
220 | - { |
|
221 | - $relations[$relation] = 'delete'; |
|
222 | - } |
|
223 | - } |
|
224 | - if (is_array($value)) |
|
225 | - { |
|
226 | - /** |
|
227 | - * Loop through the relation data. |
|
228 | - */ |
|
229 | - foreach ($value as $attr => $val) |
|
230 | - { |
|
231 | - /** |
|
232 | - * Get the relation model. |
|
233 | - */ |
|
234 | - $relationBaseModel = \Core::$relation()->model; |
|
210 | + /** |
|
211 | + * Check if the relation is a collection. |
|
212 | + */ |
|
213 | + if (class_basename($model->$relation) == 'Collection') |
|
214 | + { |
|
215 | + /** |
|
216 | + * If the relation has no value then marke the relation data |
|
217 | + * related to the model to be deleted. |
|
218 | + */ |
|
219 | + if ( ! $value || ! count($value)) |
|
220 | + { |
|
221 | + $relations[$relation] = 'delete'; |
|
222 | + } |
|
223 | + } |
|
224 | + if (is_array($value)) |
|
225 | + { |
|
226 | + /** |
|
227 | + * Loop through the relation data. |
|
228 | + */ |
|
229 | + foreach ($value as $attr => $val) |
|
230 | + { |
|
231 | + /** |
|
232 | + * Get the relation model. |
|
233 | + */ |
|
234 | + $relationBaseModel = \Core::$relation()->model; |
|
235 | 235 | |
236 | - /** |
|
237 | - * Check if the relation is a collection. |
|
238 | - */ |
|
239 | - if (class_basename($model->$relation) == 'Collection') |
|
240 | - { |
|
241 | - /** |
|
242 | - * If the id is present in the data then select the relation model for updating, |
|
243 | - * else create new model. |
|
244 | - */ |
|
245 | - $relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel; |
|
236 | + /** |
|
237 | + * Check if the relation is a collection. |
|
238 | + */ |
|
239 | + if (class_basename($model->$relation) == 'Collection') |
|
240 | + { |
|
241 | + /** |
|
242 | + * If the id is present in the data then select the relation model for updating, |
|
243 | + * else create new model. |
|
244 | + */ |
|
245 | + $relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel; |
|
246 | 246 | |
247 | - /** |
|
248 | - * If model doesn't exists. |
|
249 | - */ |
|
250 | - if ( ! $relationModel) |
|
251 | - { |
|
252 | - \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']); |
|
253 | - } |
|
247 | + /** |
|
248 | + * If model doesn't exists. |
|
249 | + */ |
|
250 | + if ( ! $relationModel) |
|
251 | + { |
|
252 | + \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']); |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * Loop through the relation attributes. |
|
257 | - */ |
|
258 | - foreach ($val as $attr => $val) |
|
259 | - { |
|
260 | - /** |
|
261 | - * Prevent the sub relations or attributes not in the fillable. |
|
262 | - */ |
|
263 | - if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
264 | - { |
|
265 | - $relationModel->$attr = $val; |
|
266 | - } |
|
267 | - } |
|
268 | - $relations[$relation][] = $relationModel; |
|
269 | - } |
|
270 | - /** |
|
271 | - * If not collection. |
|
272 | - */ |
|
273 | - else |
|
274 | - { |
|
275 | - /** |
|
276 | - * Prevent the sub relations. |
|
277 | - */ |
|
278 | - if (gettype($val) !== 'object' && gettype($val) !== 'array') |
|
279 | - { |
|
280 | - /** |
|
281 | - * If the id is present in the data then select the relation model for updating, |
|
282 | - * else create new model. |
|
283 | - */ |
|
284 | - $relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel; |
|
255 | + /** |
|
256 | + * Loop through the relation attributes. |
|
257 | + */ |
|
258 | + foreach ($val as $attr => $val) |
|
259 | + { |
|
260 | + /** |
|
261 | + * Prevent the sub relations or attributes not in the fillable. |
|
262 | + */ |
|
263 | + if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
264 | + { |
|
265 | + $relationModel->$attr = $val; |
|
266 | + } |
|
267 | + } |
|
268 | + $relations[$relation][] = $relationModel; |
|
269 | + } |
|
270 | + /** |
|
271 | + * If not collection. |
|
272 | + */ |
|
273 | + else |
|
274 | + { |
|
275 | + /** |
|
276 | + * Prevent the sub relations. |
|
277 | + */ |
|
278 | + if (gettype($val) !== 'object' && gettype($val) !== 'array') |
|
279 | + { |
|
280 | + /** |
|
281 | + * If the id is present in the data then select the relation model for updating, |
|
282 | + * else create new model. |
|
283 | + */ |
|
284 | + $relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel; |
|
285 | 285 | |
286 | - /** |
|
287 | - * If model doesn't exists. |
|
288 | - */ |
|
289 | - if ( ! $relationModel) |
|
290 | - { |
|
291 | - \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']); |
|
292 | - } |
|
286 | + /** |
|
287 | + * If model doesn't exists. |
|
288 | + */ |
|
289 | + if ( ! $relationModel) |
|
290 | + { |
|
291 | + \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']); |
|
292 | + } |
|
293 | 293 | |
294 | - /** |
|
295 | - * Prevent attributes not in the fillable. |
|
296 | - */ |
|
297 | - if (array_search($attr, $relationModel->getFillable(), true) !== false) |
|
298 | - { |
|
299 | - $relationModel->$attr = $val; |
|
300 | - $relations[$relation] = $relationModel; |
|
301 | - } |
|
302 | - } |
|
303 | - } |
|
304 | - } |
|
305 | - } |
|
306 | - } |
|
307 | - /** |
|
308 | - * If the attribute isn't a relation and prevent attributes not in the fillable. |
|
309 | - */ |
|
310 | - else if (array_search($key, $model->getFillable(), true) !== false) |
|
311 | - { |
|
312 | - $model->$key = $value; |
|
313 | - } |
|
314 | - } |
|
315 | - /** |
|
316 | - * Save the model. |
|
317 | - */ |
|
318 | - $model->save(); |
|
294 | + /** |
|
295 | + * Prevent attributes not in the fillable. |
|
296 | + */ |
|
297 | + if (array_search($attr, $relationModel->getFillable(), true) !== false) |
|
298 | + { |
|
299 | + $relationModel->$attr = $val; |
|
300 | + $relations[$relation] = $relationModel; |
|
301 | + } |
|
302 | + } |
|
303 | + } |
|
304 | + } |
|
305 | + } |
|
306 | + } |
|
307 | + /** |
|
308 | + * If the attribute isn't a relation and prevent attributes not in the fillable. |
|
309 | + */ |
|
310 | + else if (array_search($key, $model->getFillable(), true) !== false) |
|
311 | + { |
|
312 | + $model->$key = $value; |
|
313 | + } |
|
314 | + } |
|
315 | + /** |
|
316 | + * Save the model. |
|
317 | + */ |
|
318 | + $model->save(); |
|
319 | 319 | |
320 | - /** |
|
321 | - * Loop through the relations array. |
|
322 | - */ |
|
323 | - foreach ($relations as $key => $value) |
|
324 | - { |
|
325 | - /** |
|
326 | - * If the relation is marked for delete then delete it. |
|
327 | - */ |
|
328 | - if ($value == 'delete' && $model->$key()->count()) |
|
329 | - { |
|
330 | - $model->$key()->delete(); |
|
331 | - } |
|
332 | - /** |
|
333 | - * If the relation is an array. |
|
334 | - */ |
|
335 | - else if (gettype($value) == 'array') |
|
336 | - { |
|
337 | - $ids = []; |
|
338 | - /** |
|
339 | - * Loop through the relations. |
|
340 | - */ |
|
341 | - foreach ($value as $val) |
|
342 | - { |
|
343 | - switch (class_basename($model->$key())) |
|
344 | - { |
|
345 | - /** |
|
346 | - * If the relation is one to many then update it's foreign key with |
|
347 | - * the model id and save it then add its id to ids array to delete all |
|
348 | - * relations who's id isn't in the ids array. |
|
349 | - */ |
|
350 | - case 'HasMany': |
|
351 | - $foreignKeyName = explode('.', $model->$key()->getForeignKey())[1]; |
|
352 | - $val->$foreignKeyName = $model->id; |
|
353 | - $val->save(); |
|
354 | - $ids[] = $val->id; |
|
355 | - break; |
|
320 | + /** |
|
321 | + * Loop through the relations array. |
|
322 | + */ |
|
323 | + foreach ($relations as $key => $value) |
|
324 | + { |
|
325 | + /** |
|
326 | + * If the relation is marked for delete then delete it. |
|
327 | + */ |
|
328 | + if ($value == 'delete' && $model->$key()->count()) |
|
329 | + { |
|
330 | + $model->$key()->delete(); |
|
331 | + } |
|
332 | + /** |
|
333 | + * If the relation is an array. |
|
334 | + */ |
|
335 | + else if (gettype($value) == 'array') |
|
336 | + { |
|
337 | + $ids = []; |
|
338 | + /** |
|
339 | + * Loop through the relations. |
|
340 | + */ |
|
341 | + foreach ($value as $val) |
|
342 | + { |
|
343 | + switch (class_basename($model->$key())) |
|
344 | + { |
|
345 | + /** |
|
346 | + * If the relation is one to many then update it's foreign key with |
|
347 | + * the model id and save it then add its id to ids array to delete all |
|
348 | + * relations who's id isn't in the ids array. |
|
349 | + */ |
|
350 | + case 'HasMany': |
|
351 | + $foreignKeyName = explode('.', $model->$key()->getForeignKey())[1]; |
|
352 | + $val->$foreignKeyName = $model->id; |
|
353 | + $val->save(); |
|
354 | + $ids[] = $val->id; |
|
355 | + break; |
|
356 | 356 | |
357 | - /** |
|
358 | - * If the relation is many to many then add it's id to the ids array to |
|
359 | - * attache these ids to the model. |
|
360 | - */ |
|
361 | - case 'BelongsToMany': |
|
362 | - $val->save(); |
|
363 | - $ids[] = $val->id; |
|
364 | - break; |
|
365 | - } |
|
366 | - } |
|
367 | - switch (class_basename($model->$key())) |
|
368 | - { |
|
369 | - /** |
|
370 | - * If the relation is one to many then delete all |
|
371 | - * relations who's id isn't in the ids array. |
|
372 | - */ |
|
373 | - case 'HasMany': |
|
374 | - $model->$key()->whereNotIn('id', $ids)->delete(); |
|
375 | - break; |
|
357 | + /** |
|
358 | + * If the relation is many to many then add it's id to the ids array to |
|
359 | + * attache these ids to the model. |
|
360 | + */ |
|
361 | + case 'BelongsToMany': |
|
362 | + $val->save(); |
|
363 | + $ids[] = $val->id; |
|
364 | + break; |
|
365 | + } |
|
366 | + } |
|
367 | + switch (class_basename($model->$key())) |
|
368 | + { |
|
369 | + /** |
|
370 | + * If the relation is one to many then delete all |
|
371 | + * relations who's id isn't in the ids array. |
|
372 | + */ |
|
373 | + case 'HasMany': |
|
374 | + $model->$key()->whereNotIn('id', $ids)->delete(); |
|
375 | + break; |
|
376 | 376 | |
377 | - /** |
|
378 | - * If the relation is many to many then |
|
379 | - * detach the previous data and attach |
|
380 | - * the ids array to the model. |
|
381 | - */ |
|
382 | - case 'BelongsToMany': |
|
383 | - $model->$key()->detach(); |
|
384 | - $model->$key()->attach($ids); |
|
385 | - break; |
|
386 | - } |
|
387 | - } |
|
388 | - /** |
|
389 | - * If the relation isn't array. |
|
390 | - */ |
|
391 | - else |
|
392 | - { |
|
393 | - switch (class_basename($model->$key())) |
|
394 | - { |
|
395 | - /** |
|
396 | - * If the relation is one to many or one to one. |
|
397 | - */ |
|
398 | - case 'BelongsTo': |
|
399 | - $value->save(); |
|
400 | - $model->$key()->associate($value); |
|
401 | - $model->save(); |
|
402 | - break; |
|
403 | - } |
|
404 | - } |
|
405 | - } |
|
377 | + /** |
|
378 | + * If the relation is many to many then |
|
379 | + * detach the previous data and attach |
|
380 | + * the ids array to the model. |
|
381 | + */ |
|
382 | + case 'BelongsToMany': |
|
383 | + $model->$key()->detach(); |
|
384 | + $model->$key()->attach($ids); |
|
385 | + break; |
|
386 | + } |
|
387 | + } |
|
388 | + /** |
|
389 | + * If the relation isn't array. |
|
390 | + */ |
|
391 | + else |
|
392 | + { |
|
393 | + switch (class_basename($model->$key())) |
|
394 | + { |
|
395 | + /** |
|
396 | + * If the relation is one to many or one to one. |
|
397 | + */ |
|
398 | + case 'BelongsTo': |
|
399 | + $value->save(); |
|
400 | + $model->$key()->associate($value); |
|
401 | + $model->save(); |
|
402 | + break; |
|
403 | + } |
|
404 | + } |
|
405 | + } |
|
406 | 406 | |
407 | - $saveLog ? \Logging::saveLog(array_key_exists('id', $data) ? 'update' : 'create', class_basename($modelClass), $this->getModel(), $model->id, $model) : false; |
|
408 | - }); |
|
407 | + $saveLog ? \Logging::saveLog(array_key_exists('id', $data) ? 'update' : 'create', class_basename($modelClass), $this->getModel(), $model->id, $model) : false; |
|
408 | + }); |
|
409 | 409 | |
410 | - /** |
|
411 | - * return the saved mdel with the given relations. |
|
412 | - */ |
|
413 | - return $this->find($model->id, $with); |
|
414 | - } |
|
410 | + /** |
|
411 | + * return the saved mdel with the given relations. |
|
412 | + */ |
|
413 | + return $this->find($model->id, $with); |
|
414 | + } |
|
415 | 415 | |
416 | - /** |
|
417 | - * Delete record from the storage based on the given |
|
418 | - * condition. |
|
419 | - * |
|
420 | - * @param var $value condition value |
|
421 | - * @param string $attribute condition column name |
|
422 | - * @return void |
|
423 | - */ |
|
424 | - public function delete($value, $attribute = 'id', $saveLog = true) |
|
425 | - { |
|
426 | - if ($attribute == 'id') |
|
427 | - { |
|
428 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
429 | - $model = $this->model->lockForUpdate()->find($value); |
|
430 | - if ( ! $model) |
|
431 | - { |
|
432 | - \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value); |
|
433 | - } |
|
416 | + /** |
|
417 | + * Delete record from the storage based on the given |
|
418 | + * condition. |
|
419 | + * |
|
420 | + * @param var $value condition value |
|
421 | + * @param string $attribute condition column name |
|
422 | + * @return void |
|
423 | + */ |
|
424 | + public function delete($value, $attribute = 'id', $saveLog = true) |
|
425 | + { |
|
426 | + if ($attribute == 'id') |
|
427 | + { |
|
428 | + \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
429 | + $model = $this->model->lockForUpdate()->find($value); |
|
430 | + if ( ! $model) |
|
431 | + { |
|
432 | + \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value); |
|
433 | + } |
|
434 | 434 | |
435 | - $model->delete(); |
|
436 | - $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false; |
|
437 | - }); |
|
438 | - } |
|
439 | - else |
|
440 | - { |
|
441 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
442 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){ |
|
443 | - $model->delete(); |
|
444 | - $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
|
445 | - }); |
|
446 | - }); |
|
447 | - } |
|
448 | - } |
|
435 | + $model->delete(); |
|
436 | + $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false; |
|
437 | + }); |
|
438 | + } |
|
439 | + else |
|
440 | + { |
|
441 | + \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
442 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){ |
|
443 | + $model->delete(); |
|
444 | + $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
|
445 | + }); |
|
446 | + }); |
|
447 | + } |
|
448 | + } |
|
449 | 449 | |
450 | - /** |
|
451 | - * Fetch records from the storage based on the given |
|
452 | - * id. |
|
453 | - * |
|
454 | - * @param integer $id |
|
455 | - * @param array $relations |
|
456 | - * @param array $columns |
|
457 | - * @return object |
|
458 | - */ |
|
459 | - public function find($id, $relations = [], $columns = array('*')) |
|
460 | - { |
|
461 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns); |
|
462 | - } |
|
450 | + /** |
|
451 | + * Fetch records from the storage based on the given |
|
452 | + * id. |
|
453 | + * |
|
454 | + * @param integer $id |
|
455 | + * @param array $relations |
|
456 | + * @param array $columns |
|
457 | + * @return object |
|
458 | + */ |
|
459 | + public function find($id, $relations = [], $columns = array('*')) |
|
460 | + { |
|
461 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns); |
|
462 | + } |
|
463 | 463 | |
464 | - /** |
|
465 | - * Fetch records from the storage based on the given |
|
466 | - * condition. |
|
467 | - * |
|
468 | - * @param array $conditions array of conditions |
|
469 | - * @param array $relations |
|
470 | - * @param string $sortBy |
|
471 | - * @param boolean $desc |
|
472 | - * @param array $columns |
|
473 | - * @return collection |
|
474 | - */ |
|
475 | - public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
476 | - { |
|
477 | - $conditions = $this->constructConditions($conditions); |
|
478 | - $sort = $desc ? 'desc' : 'asc'; |
|
479 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
480 | - } |
|
464 | + /** |
|
465 | + * Fetch records from the storage based on the given |
|
466 | + * condition. |
|
467 | + * |
|
468 | + * @param array $conditions array of conditions |
|
469 | + * @param array $relations |
|
470 | + * @param string $sortBy |
|
471 | + * @param boolean $desc |
|
472 | + * @param array $columns |
|
473 | + * @return collection |
|
474 | + */ |
|
475 | + public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
|
476 | + { |
|
477 | + $conditions = $this->constructConditions($conditions); |
|
478 | + $sort = $desc ? 'desc' : 'asc'; |
|
479 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
480 | + } |
|
481 | 481 | |
482 | - /** |
|
483 | - * Fetch the first record from the storage based on the given |
|
484 | - * condition. |
|
485 | - * |
|
486 | - * @param array $conditions array of conditions |
|
487 | - * @param array $relations |
|
488 | - * @param array $columns |
|
489 | - * @return object |
|
490 | - */ |
|
491 | - public function first($conditions, $relations = [], $columns = array('*')) |
|
492 | - { |
|
493 | - $conditions = $this->constructConditions($conditions); |
|
494 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns); |
|
495 | - } |
|
482 | + /** |
|
483 | + * Fetch the first record from the storage based on the given |
|
484 | + * condition. |
|
485 | + * |
|
486 | + * @param array $conditions array of conditions |
|
487 | + * @param array $relations |
|
488 | + * @param array $columns |
|
489 | + * @return object |
|
490 | + */ |
|
491 | + public function first($conditions, $relations = [], $columns = array('*')) |
|
492 | + { |
|
493 | + $conditions = $this->constructConditions($conditions); |
|
494 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns); |
|
495 | + } |
|
496 | 496 | |
497 | - /** |
|
498 | - * Build the conditions recursively for the retrieving methods. |
|
499 | - * @param array $conditions |
|
500 | - * @return array |
|
501 | - */ |
|
502 | - protected function constructConditions($conditions) |
|
503 | - { |
|
504 | - $conditionString = ''; |
|
505 | - $conditionValues = []; |
|
506 | - foreach ($conditions as $key => $value) |
|
507 | - { |
|
508 | - if ($key == 'and') |
|
509 | - { |
|
510 | - $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
511 | - $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
|
512 | - } |
|
513 | - else if ($key == 'or') |
|
514 | - { |
|
515 | - $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
516 | - $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
|
517 | - } |
|
518 | - else |
|
519 | - { |
|
520 | - $conditionString .= $key . '=? {op} '; |
|
521 | - $conditionValues[] = $value; |
|
522 | - } |
|
523 | - } |
|
524 | - $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
525 | - return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
|
526 | - } |
|
497 | + /** |
|
498 | + * Build the conditions recursively for the retrieving methods. |
|
499 | + * @param array $conditions |
|
500 | + * @return array |
|
501 | + */ |
|
502 | + protected function constructConditions($conditions) |
|
503 | + { |
|
504 | + $conditionString = ''; |
|
505 | + $conditionValues = []; |
|
506 | + foreach ($conditions as $key => $value) |
|
507 | + { |
|
508 | + if ($key == 'and') |
|
509 | + { |
|
510 | + $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
511 | + $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
|
512 | + } |
|
513 | + else if ($key == 'or') |
|
514 | + { |
|
515 | + $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
516 | + $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
|
517 | + } |
|
518 | + else |
|
519 | + { |
|
520 | + $conditionString .= $key . '=? {op} '; |
|
521 | + $conditionValues[] = $value; |
|
522 | + } |
|
523 | + } |
|
524 | + $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
525 | + return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
|
526 | + } |
|
527 | 527 | |
528 | - /** |
|
529 | - * Abstract method that return the necessary |
|
530 | - * information (full model namespace) |
|
531 | - * needed to preform the previous actions. |
|
532 | - * |
|
533 | - * @return string |
|
534 | - */ |
|
535 | - abstract protected function getModel(); |
|
528 | + /** |
|
529 | + * Abstract method that return the necessary |
|
530 | + * information (full model namespace) |
|
531 | + * needed to preform the previous actions. |
|
532 | + * |
|
533 | + * @return string |
|
534 | + */ |
|
535 | + abstract protected function getModel(); |
|
536 | 536 | } |
537 | 537 | \ No newline at end of file |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * Construct the select conditions for the model. |
65 | 65 | */ |
66 | - $model->where(function ($q) use ($query, $conditionColumns, $relations){ |
|
66 | + $model->where(function($q) use ($query, $conditionColumns, $relations){ |
|
67 | 67 | |
68 | 68 | /** |
69 | 69 | * Use the first element in the model columns to construct the first condition. |
70 | 70 | */ |
71 | - $q->where(\DB::raw('LOWER(' . array_shift($conditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
71 | + $q->where(\DB::raw('LOWER('.array_shift($conditionColumns).')'), 'LIKE', '%'.strtolower($query).'%'); |
|
72 | 72 | |
73 | 73 | /** |
74 | 74 | * Loop through the rest of the columns to construct or where conditions. |
75 | 75 | */ |
76 | 76 | foreach ($conditionColumns as $column) |
77 | 77 | { |
78 | - $q->orWhere(\DB::raw('LOWER(' . $column . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
78 | + $q->orWhere(\DB::raw('LOWER('.$column.')'), 'LIKE', '%'.strtolower($query).'%'); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | /** |
97 | 97 | * Construct the relation condition. |
98 | 98 | */ |
99 | - $q->orWhereHas($relation, function ($subModel) use ($query, $relation){ |
|
99 | + $q->orWhereHas($relation, function($subModel) use ($query, $relation){ |
|
100 | 100 | |
101 | - $subModel->where(function ($q) use ($query, $relation){ |
|
101 | + $subModel->where(function($q) use ($query, $relation){ |
|
102 | 102 | |
103 | 103 | /** |
104 | 104 | * Get columns of the relation. |
@@ -108,14 +108,14 @@ discard block |
||
108 | 108 | /** |
109 | 109 | * Use the first element in the relation model columns to construct the first condition. |
110 | 110 | */ |
111 | - $q->where(\DB::raw('LOWER(' . array_shift($subConditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
111 | + $q->where(\DB::raw('LOWER('.array_shift($subConditionColumns).')'), 'LIKE', '%'.strtolower($query).'%'); |
|
112 | 112 | |
113 | 113 | /** |
114 | 114 | * Loop through the rest of the columns to construct or where conditions. |
115 | 115 | */ |
116 | 116 | foreach ($subConditionColumns as $subConditionColumn) |
117 | 117 | { |
118 | - $q->orWhere(\DB::raw('LOWER(' . $subConditionColumn . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
118 | + $q->orWhere(\DB::raw('LOWER('.$subConditionColumn.')'), 'LIKE', '%'.strtolower($query).'%'); |
|
119 | 119 | } |
120 | 120 | }); |
121 | 121 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | $relations = []; |
178 | 178 | $with = []; |
179 | 179 | |
180 | - \DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) { |
|
180 | + \DB::transaction(function() use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) { |
|
181 | 181 | /** |
182 | 182 | * If the id is present in the data then select the model for updating, |
183 | 183 | * else create new model. |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
187 | 187 | if ( ! $model) |
188 | 188 | { |
189 | - \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']); |
|
189 | + \ErrorHandler::notFound(class_basename($modelClass).' with id : '.$data['id']); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | */ |
250 | 250 | if ( ! $relationModel) |
251 | 251 | { |
252 | - \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']); |
|
252 | + \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | /** |
261 | 261 | * Prevent the sub relations or attributes not in the fillable. |
262 | 262 | */ |
263 | - if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
263 | + if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
264 | 264 | { |
265 | 265 | $relationModel->$attr = $val; |
266 | 266 | } |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | */ |
289 | 289 | if ( ! $relationModel) |
290 | 290 | { |
291 | - \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']); |
|
291 | + \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -425,11 +425,11 @@ discard block |
||
425 | 425 | { |
426 | 426 | if ($attribute == 'id') |
427 | 427 | { |
428 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
428 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
429 | 429 | $model = $this->model->lockForUpdate()->find($value); |
430 | 430 | if ( ! $model) |
431 | 431 | { |
432 | - \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value); |
|
432 | + \ErrorHandler::notFound(class_basename($this->model).' with id : '.$value); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | $model->delete(); |
@@ -438,8 +438,8 @@ discard block |
||
438 | 438 | } |
439 | 439 | else |
440 | 440 | { |
441 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
442 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){ |
|
441 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
442 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) { |
|
443 | 443 | $model->delete(); |
444 | 444 | $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
445 | 445 | }); |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | { |
477 | 477 | $conditions = $this->constructConditions($conditions); |
478 | 478 | $sort = $desc ? 'desc' : 'asc'; |
479 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
479 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | /** |
@@ -507,21 +507,21 @@ discard block |
||
507 | 507 | { |
508 | 508 | if ($key == 'and') |
509 | 509 | { |
510 | - $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
510 | + $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']).' {op} '; |
|
511 | 511 | $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
512 | 512 | } |
513 | 513 | else if ($key == 'or') |
514 | 514 | { |
515 | - $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
515 | + $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']).' {op} '; |
|
516 | 516 | $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
517 | 517 | } |
518 | 518 | else |
519 | 519 | { |
520 | - $conditionString .= $key . '=? {op} '; |
|
520 | + $conditionString .= $key.'=? {op} '; |
|
521 | 521 | $conditionValues[] = $value; |
522 | 522 | } |
523 | 523 | } |
524 | - $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
524 | + $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
525 | 525 | return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
526 | 526 | } |
527 | 527 |
@@ -5,65 +5,65 @@ |
||
5 | 5 | */ |
6 | 6 | class AclGroupObserver { |
7 | 7 | |
8 | - public function saving($model) |
|
9 | - { |
|
10 | - // |
|
11 | - } |
|
8 | + public function saving($model) |
|
9 | + { |
|
10 | + // |
|
11 | + } |
|
12 | 12 | |
13 | - public function saved($model) |
|
14 | - { |
|
15 | - // |
|
16 | - } |
|
13 | + public function saved($model) |
|
14 | + { |
|
15 | + // |
|
16 | + } |
|
17 | 17 | |
18 | - public function creating($model) |
|
19 | - { |
|
20 | - // |
|
21 | - } |
|
18 | + public function creating($model) |
|
19 | + { |
|
20 | + // |
|
21 | + } |
|
22 | 22 | |
23 | - public function created($model) |
|
24 | - { |
|
25 | - // |
|
26 | - } |
|
23 | + public function created($model) |
|
24 | + { |
|
25 | + // |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Prevent updating of the admin group. |
|
30 | - * |
|
31 | - * @param object $model the model beign updated. |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public function updating($model) |
|
35 | - { |
|
36 | - if ($model->getOriginal()['name'] == 'Admin') |
|
37 | - { |
|
38 | - \ErrorHandler::noPermissions(); |
|
39 | - } |
|
40 | - } |
|
28 | + /** |
|
29 | + * Prevent updating of the admin group. |
|
30 | + * |
|
31 | + * @param object $model the model beign updated. |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public function updating($model) |
|
35 | + { |
|
36 | + if ($model->getOriginal()['name'] == 'Admin') |
|
37 | + { |
|
38 | + \ErrorHandler::noPermissions(); |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | - public function updated($model) |
|
43 | - { |
|
44 | - // |
|
45 | - } |
|
42 | + public function updated($model) |
|
43 | + { |
|
44 | + // |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Soft delete the associated permissions to the deleted group |
|
49 | - * and prevent deleting the admin group. |
|
50 | - * |
|
51 | - * @param object $model the delted model. |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function deleting($model) |
|
55 | - { |
|
56 | - if ($model->getOriginal()['name'] == 'Admin') |
|
57 | - { |
|
58 | - \ErrorHandler::noPermissions(); |
|
59 | - } |
|
47 | + /** |
|
48 | + * Soft delete the associated permissions to the deleted group |
|
49 | + * and prevent deleting the admin group. |
|
50 | + * |
|
51 | + * @param object $model the delted model. |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function deleting($model) |
|
55 | + { |
|
56 | + if ($model->getOriginal()['name'] == 'Admin') |
|
57 | + { |
|
58 | + \ErrorHandler::noPermissions(); |
|
59 | + } |
|
60 | 60 | |
61 | - \DB::table('groups_permissions')->where('group_id', $model->id)->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
62 | - } |
|
61 | + \DB::table('groups_permissions')->where('group_id', $model->id)->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
62 | + } |
|
63 | 63 | |
64 | - public function deleted($model) |
|
65 | - { |
|
66 | - // |
|
67 | - } |
|
64 | + public function deleted($model) |
|
65 | + { |
|
66 | + // |
|
67 | + } |
|
68 | 68 | |
69 | 69 | } |
70 | 70 | \ No newline at end of file |
@@ -5,59 +5,59 @@ |
||
5 | 5 | */ |
6 | 6 | class SettingsObserver { |
7 | 7 | |
8 | - public function saving($model) |
|
9 | - { |
|
10 | - // |
|
11 | - } |
|
12 | - |
|
13 | - public function saved($model) |
|
14 | - { |
|
15 | - // |
|
16 | - } |
|
17 | - |
|
18 | - /** |
|
19 | - * Prevent the creating of the settings. |
|
20 | - * |
|
21 | - * @param object $model the model beign created. |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function creating($model) |
|
25 | - { |
|
26 | - \ErrorHandler::cannotCreateSetting(); |
|
27 | - } |
|
28 | - |
|
29 | - public function created($model) |
|
30 | - { |
|
31 | - // |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * Prevent updating of the setting key. |
|
36 | - * |
|
37 | - * @param object $model the model beign updated. |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - public function updating($model) |
|
41 | - { |
|
42 | - if ($model->getOriginal()['key'] !== $model->key) |
|
43 | - { |
|
44 | - \ErrorHandler::cannotUpdateSettingKey(); |
|
45 | - } |
|
46 | - } |
|
47 | - |
|
48 | - public function updated($model) |
|
49 | - { |
|
50 | - // |
|
51 | - } |
|
52 | - |
|
53 | - public function deleting($model) |
|
54 | - { |
|
55 | - // |
|
56 | - } |
|
57 | - |
|
58 | - public function deleted($model) |
|
59 | - { |
|
60 | - // |
|
61 | - } |
|
8 | + public function saving($model) |
|
9 | + { |
|
10 | + // |
|
11 | + } |
|
12 | + |
|
13 | + public function saved($model) |
|
14 | + { |
|
15 | + // |
|
16 | + } |
|
17 | + |
|
18 | + /** |
|
19 | + * Prevent the creating of the settings. |
|
20 | + * |
|
21 | + * @param object $model the model beign created. |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function creating($model) |
|
25 | + { |
|
26 | + \ErrorHandler::cannotCreateSetting(); |
|
27 | + } |
|
28 | + |
|
29 | + public function created($model) |
|
30 | + { |
|
31 | + // |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * Prevent updating of the setting key. |
|
36 | + * |
|
37 | + * @param object $model the model beign updated. |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + public function updating($model) |
|
41 | + { |
|
42 | + if ($model->getOriginal()['key'] !== $model->key) |
|
43 | + { |
|
44 | + \ErrorHandler::cannotUpdateSettingKey(); |
|
45 | + } |
|
46 | + } |
|
47 | + |
|
48 | + public function updated($model) |
|
49 | + { |
|
50 | + // |
|
51 | + } |
|
52 | + |
|
53 | + public function deleting($model) |
|
54 | + { |
|
55 | + // |
|
56 | + } |
|
57 | + |
|
58 | + public function deleted($model) |
|
59 | + { |
|
60 | + // |
|
61 | + } |
|
62 | 62 | |
63 | 63 | } |
64 | 64 | \ No newline at end of file |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | * @param array $relations |
9 | 9 | * @param array $sortBy |
10 | - * @param array $desc |
|
10 | + * @param integer $desc |
|
11 | 11 | * @param array $columns |
12 | 12 | * @return collection |
13 | 13 | */ |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param integer $perPage |
22 | 22 | * @param array $relations |
23 | 23 | * @param array $sortBy |
24 | - * @param array $desc |
|
24 | + * @param integer $desc |
|
25 | 25 | * @param array $columns |
26 | 26 | * @return collection |
27 | 27 | */ |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param integer $perPage |
34 | 34 | * @param array $relations |
35 | 35 | * @param array $sortBy |
36 | - * @param array $desc |
|
36 | + * @param integer $desc |
|
37 | 37 | * @param array $columns |
38 | 38 | * @return collection |
39 | 39 | */ |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @param integer $perPage |
48 | 48 | * @param array $relations |
49 | 49 | * @param array $sortBy |
50 | - * @param array $desc |
|
50 | + * @param integer $desc |
|
51 | 51 | * @param array $columns |
52 | 52 | * @return collection |
53 | 53 | */ |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param array $conditions array of conditions |
91 | 91 | * @param array $relations |
92 | 92 | * @param array $sortBy |
93 | - * @param array $desc |
|
93 | + * @param integer $desc |
|
94 | 94 | * @param array $columns |
95 | 95 | * @return collection |
96 | 96 | */ |
@@ -3,107 +3,107 @@ |
||
3 | 3 | interface RepositoryInterface |
4 | 4 | { |
5 | 5 | /** |
6 | - * Fetch all records with relations from the storage. |
|
7 | - * |
|
8 | - * @param array $relations |
|
9 | - * @param array $sortBy |
|
10 | - * @param array $desc |
|
11 | - * @param array $columns |
|
12 | - * @return collection |
|
13 | - */ |
|
6 | + * Fetch all records with relations from the storage. |
|
7 | + * |
|
8 | + * @param array $relations |
|
9 | + * @param array $sortBy |
|
10 | + * @param array $desc |
|
11 | + * @param array $columns |
|
12 | + * @return collection |
|
13 | + */ |
|
14 | 14 | public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
15 | 15 | |
16 | - /** |
|
17 | - * Fetch all records with relations from storage in pages |
|
18 | - * that matche the given query. |
|
19 | - * |
|
20 | - * @param string $query |
|
21 | - * @param integer $perPage |
|
22 | - * @param array $relations |
|
23 | - * @param array $sortBy |
|
24 | - * @param array $desc |
|
25 | - * @param array $columns |
|
26 | - * @return collection |
|
27 | - */ |
|
28 | - public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
16 | + /** |
|
17 | + * Fetch all records with relations from storage in pages |
|
18 | + * that matche the given query. |
|
19 | + * |
|
20 | + * @param string $query |
|
21 | + * @param integer $perPage |
|
22 | + * @param array $relations |
|
23 | + * @param array $sortBy |
|
24 | + * @param array $desc |
|
25 | + * @param array $columns |
|
26 | + * @return collection |
|
27 | + */ |
|
28 | + public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
29 | 29 | |
30 | 30 | /** |
31 | - * Fetch all records with relations from storage in pages. |
|
32 | - * |
|
33 | - * @param integer $perPage |
|
34 | - * @param array $relations |
|
35 | - * @param array $sortBy |
|
36 | - * @param array $desc |
|
37 | - * @param array $columns |
|
38 | - * @return collection |
|
39 | - */ |
|
40 | - public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
31 | + * Fetch all records with relations from storage in pages. |
|
32 | + * |
|
33 | + * @param integer $perPage |
|
34 | + * @param array $relations |
|
35 | + * @param array $sortBy |
|
36 | + * @param array $desc |
|
37 | + * @param array $columns |
|
38 | + * @return collection |
|
39 | + */ |
|
40 | + public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
41 | 41 | |
42 | 42 | /** |
43 | - * Fetch all records with relations based on |
|
44 | - * the given condition from storage in pages. |
|
45 | - * |
|
46 | - * @param array $conditions array of conditions |
|
47 | - * @param integer $perPage |
|
48 | - * @param array $relations |
|
49 | - * @param array $sortBy |
|
50 | - * @param array $desc |
|
51 | - * @param array $columns |
|
52 | - * @return collection |
|
53 | - */ |
|
54 | - public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
43 | + * Fetch all records with relations based on |
|
44 | + * the given condition from storage in pages. |
|
45 | + * |
|
46 | + * @param array $conditions array of conditions |
|
47 | + * @param integer $perPage |
|
48 | + * @param array $relations |
|
49 | + * @param array $sortBy |
|
50 | + * @param array $desc |
|
51 | + * @param array $columns |
|
52 | + * @return collection |
|
53 | + */ |
|
54 | + public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
55 | 55 | |
56 | - /** |
|
57 | - * Save the given model/models to the storage. |
|
58 | - * |
|
59 | - * @param array $data |
|
60 | - * @param boolean $saveLog |
|
61 | - * @return object |
|
62 | - */ |
|
63 | - public function save(array $data, $saveLog = true); |
|
56 | + /** |
|
57 | + * Save the given model/models to the storage. |
|
58 | + * |
|
59 | + * @param array $data |
|
60 | + * @param boolean $saveLog |
|
61 | + * @return object |
|
62 | + */ |
|
63 | + public function save(array $data, $saveLog = true); |
|
64 | 64 | |
65 | 65 | /** |
66 | - * Delete record from the storage based on the given |
|
67 | - * condition. |
|
68 | - * |
|
69 | - * @param var $value condition value |
|
70 | - * @param string $attribute condition column name |
|
71 | - * @return integer affected rows |
|
72 | - */ |
|
73 | - public function delete($value, $attribute = 'id'); |
|
66 | + * Delete record from the storage based on the given |
|
67 | + * condition. |
|
68 | + * |
|
69 | + * @param var $value condition value |
|
70 | + * @param string $attribute condition column name |
|
71 | + * @return integer affected rows |
|
72 | + */ |
|
73 | + public function delete($value, $attribute = 'id'); |
|
74 | 74 | |
75 | 75 | /** |
76 | - * Fetch records from the storage based on the given |
|
77 | - * id. |
|
78 | - * |
|
79 | - * @param integer $id |
|
80 | - * @param array $relations |
|
81 | - * @param array $columns |
|
82 | - * @return object |
|
83 | - */ |
|
84 | - public function find($id, $relations = [], $columns = array('*')); |
|
76 | + * Fetch records from the storage based on the given |
|
77 | + * id. |
|
78 | + * |
|
79 | + * @param integer $id |
|
80 | + * @param array $relations |
|
81 | + * @param array $columns |
|
82 | + * @return object |
|
83 | + */ |
|
84 | + public function find($id, $relations = [], $columns = array('*')); |
|
85 | 85 | |
86 | 86 | /** |
87 | - * Fetch records from the storage based on the given |
|
88 | - * condition. |
|
89 | - * |
|
90 | - * @param array $conditions array of conditions |
|
91 | - * @param array $relations |
|
92 | - * @param array $sortBy |
|
93 | - * @param array $desc |
|
94 | - * @param array $columns |
|
95 | - * @return collection |
|
96 | - */ |
|
97 | - public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
87 | + * Fetch records from the storage based on the given |
|
88 | + * condition. |
|
89 | + * |
|
90 | + * @param array $conditions array of conditions |
|
91 | + * @param array $relations |
|
92 | + * @param array $sortBy |
|
93 | + * @param array $desc |
|
94 | + * @param array $columns |
|
95 | + * @return collection |
|
96 | + */ |
|
97 | + public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
98 | 98 | |
99 | - /** |
|
100 | - * Fetch the first record fro the storage based on the given |
|
101 | - * condition. |
|
102 | - * |
|
103 | - * @param array $conditions array of conditions |
|
104 | - * @param array $relations |
|
105 | - * @param array $columns |
|
106 | - * @return object |
|
107 | - */ |
|
108 | - public function first($conditions, $relations = [], $columns = array('*')); |
|
99 | + /** |
|
100 | + * Fetch the first record fro the storage based on the given |
|
101 | + * condition. |
|
102 | + * |
|
103 | + * @param array $conditions array of conditions |
|
104 | + * @param array $relations |
|
105 | + * @param array $columns |
|
106 | + * @return object |
|
107 | + */ |
|
108 | + public function first($conditions, $relations = [], $columns = array('*')); |
|
109 | 109 | } |
110 | 110 | \ No newline at end of file |
@@ -15,23 +15,23 @@ |
||
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
18 | - * Set the notification notified to true. |
|
19 | - * |
|
20 | - * @param integer $id |
|
21 | - * @return object |
|
22 | - */ |
|
23 | - public function notified($id) |
|
24 | - { |
|
25 | - return $this->save(['id' => $id, 'notified' => 1]); |
|
26 | - } |
|
18 | + * Set the notification notified to true. |
|
19 | + * |
|
20 | + * @param integer $id |
|
21 | + * @return object |
|
22 | + */ |
|
23 | + public function notified($id) |
|
24 | + { |
|
25 | + return $this->save(['id' => $id, 'notified' => 1]); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Set the notification notified to all. |
|
30 | - * |
|
31 | - * @return void |
|
32 | - */ |
|
33 | - public function notifyAll() |
|
34 | - { |
|
35 | - \Core::notifications()->update(false, ['notified' => 1], 'notified'); |
|
36 | - } |
|
28 | + /** |
|
29 | + * Set the notification notified to all. |
|
30 | + * |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + public function notifyAll() |
|
34 | + { |
|
35 | + \Core::notifications()->update(false, ['notified' => 1], 'notified'); |
|
36 | + } |
|
37 | 37 | } |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | use App\Modules\V1\Core\AbstractRepositories\AbstractRepositoryContainer; |
4 | 4 | |
5 | -class Core extends AbstractRepositoryContainer{ |
|
5 | +class Core extends AbstractRepositoryContainer { |
|
6 | 6 | /** |
7 | 7 | * Specify module repositories name space. |
8 | 8 | * |
@@ -2,17 +2,17 @@ |
||
2 | 2 | |
3 | 3 | class Logging |
4 | 4 | { |
5 | - public function saveLog($action, $item_name, $item_type, $item_id) |
|
6 | - { |
|
7 | - if (\Core::logs() && $item_name !== 'Log') |
|
8 | - { |
|
9 | - \Core::logs()->save([ |
|
10 | - 'action' => $action, |
|
11 | - 'item_name' => $item_name, |
|
12 | - 'item_type' => $item_type, |
|
13 | - 'item_id' => $item_id, |
|
14 | - 'user_id' => \JWTAuth::parseToken()->authenticate()->id, |
|
15 | - ], false, false); |
|
16 | - } |
|
17 | - } |
|
5 | + public function saveLog($action, $item_name, $item_type, $item_id) |
|
6 | + { |
|
7 | + if (\Core::logs() && $item_name !== 'Log') |
|
8 | + { |
|
9 | + \Core::logs()->save([ |
|
10 | + 'action' => $action, |
|
11 | + 'item_name' => $item_name, |
|
12 | + 'item_type' => $item_type, |
|
13 | + 'item_id' => $item_id, |
|
14 | + 'user_id' => \JWTAuth::parseToken()->authenticate()->id, |
|
15 | + ], false, false); |
|
16 | + } |
|
17 | + } |
|
18 | 18 | } |
19 | 19 | \ No newline at end of file |
@@ -5,36 +5,36 @@ |
||
5 | 5 | |
6 | 6 | class Notification extends Model{ |
7 | 7 | |
8 | - use SoftDeletes; |
|
9 | - protected $table = 'push_notifications_devices'; |
|
10 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
11 | - protected $hidden = ['deleted_at']; |
|
12 | - protected $guarded = ['id']; |
|
13 | - protected $fillable = ['device_token', 'device_type', 'user_id', 'active']; |
|
8 | + use SoftDeletes; |
|
9 | + protected $table = 'push_notifications_devices'; |
|
10 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
11 | + protected $hidden = ['deleted_at']; |
|
12 | + protected $guarded = ['id']; |
|
13 | + protected $fillable = ['device_token', 'device_type', 'user_id', 'active']; |
|
14 | 14 | |
15 | - public function getCreatedAtAttribute($value) |
|
16 | - { |
|
17 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
18 | - } |
|
15 | + public function getCreatedAtAttribute($value) |
|
16 | + { |
|
17 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
18 | + } |
|
19 | 19 | |
20 | - public function getUpdatedAtAttribute($value) |
|
21 | - { |
|
22 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
23 | - } |
|
20 | + public function getUpdatedAtAttribute($value) |
|
21 | + { |
|
22 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
23 | + } |
|
24 | 24 | |
25 | - public function getDeletedAtAttribute($value) |
|
26 | - { |
|
27 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
28 | - } |
|
25 | + public function getDeletedAtAttribute($value) |
|
26 | + { |
|
27 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
28 | + } |
|
29 | 29 | |
30 | - public function user() |
|
31 | - { |
|
32 | - return $this->belongsTo('App\Modules\V1\Acl\AclUser'); |
|
33 | - } |
|
30 | + public function user() |
|
31 | + { |
|
32 | + return $this->belongsTo('App\Modules\V1\Acl\AclUser'); |
|
33 | + } |
|
34 | 34 | |
35 | - public static function boot() |
|
36 | - { |
|
37 | - parent::boot(); |
|
38 | - parent::observe(\App::make('App\Modules\V1\Notifications\ModelObservers\PushNotificationDeviceObserver')); |
|
39 | - } |
|
35 | + public static function boot() |
|
36 | + { |
|
37 | + parent::boot(); |
|
38 | + parent::observe(\App::make('App\Modules\V1\Notifications\ModelObservers\PushNotificationDeviceObserver')); |
|
39 | + } |
|
40 | 40 | } |
@@ -3,7 +3,7 @@ |
||
3 | 3 | use Illuminate\Database\Eloquent\Model; |
4 | 4 | use Illuminate\Database\Eloquent\SoftDeletes; |
5 | 5 | |
6 | -class PushNotificationDevice extends Model{ |
|
6 | +class PushNotificationDevice extends Model { |
|
7 | 7 | |
8 | 8 | use SoftDeletes; |
9 | 9 | protected $table = 'push_notifications_devices'; |
@@ -5,44 +5,44 @@ |
||
5 | 5 | */ |
6 | 6 | class LogObserver { |
7 | 7 | |
8 | - public function saving($model) |
|
9 | - { |
|
10 | - // |
|
11 | - } |
|
12 | - |
|
13 | - public function saved($model) |
|
14 | - { |
|
15 | - // |
|
16 | - } |
|
17 | - |
|
18 | - public function creating($model) |
|
19 | - { |
|
20 | - // |
|
21 | - } |
|
22 | - |
|
23 | - public function created($model) |
|
24 | - { |
|
25 | - // |
|
26 | - } |
|
27 | - |
|
28 | - public function updating($model) |
|
29 | - { |
|
30 | - // |
|
31 | - } |
|
32 | - |
|
33 | - public function updated($model) |
|
34 | - { |
|
35 | - // |
|
36 | - } |
|
37 | - |
|
38 | - public function deleting($model) |
|
39 | - { |
|
40 | - // |
|
41 | - } |
|
42 | - |
|
43 | - public function deleted($model) |
|
44 | - { |
|
45 | - // |
|
46 | - } |
|
8 | + public function saving($model) |
|
9 | + { |
|
10 | + // |
|
11 | + } |
|
12 | + |
|
13 | + public function saved($model) |
|
14 | + { |
|
15 | + // |
|
16 | + } |
|
17 | + |
|
18 | + public function creating($model) |
|
19 | + { |
|
20 | + // |
|
21 | + } |
|
22 | + |
|
23 | + public function created($model) |
|
24 | + { |
|
25 | + // |
|
26 | + } |
|
27 | + |
|
28 | + public function updating($model) |
|
29 | + { |
|
30 | + // |
|
31 | + } |
|
32 | + |
|
33 | + public function updated($model) |
|
34 | + { |
|
35 | + // |
|
36 | + } |
|
37 | + |
|
38 | + public function deleting($model) |
|
39 | + { |
|
40 | + // |
|
41 | + } |
|
42 | + |
|
43 | + public function deleted($model) |
|
44 | + { |
|
45 | + // |
|
46 | + } |
|
47 | 47 | |
48 | 48 | } |
49 | 49 | \ No newline at end of file |