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