Completed
Push — master ( 4b6f70...bf5864 )
by Sherif
02:04
created
src/Modules/Core/BaseClasses/BaseRepository.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      *
28 28
      * @param  array   $relations
29 29
      * @param  string  $sortBy
30
-     * @param  boolean $desc
30
+     * @param  integer $desc
31 31
      * @param  array   $columns
32 32
      * @return collection
33 33
      */
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
      * @param  integer $perPage
44 44
      * @param  array   $relations
45 45
      * @param  string  $sortBy
46
-     * @param  boolean $desc
46
+     * @param  integer $desc
47 47
      * @param  array   $columns
48 48
      * @return collection
49 49
      */
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      * @param  integer $perPage
62 62
      * @param  array   $relations
63 63
      * @param  string  $sortBy
64
-     * @param  boolean $desc
64
+     * @param  integer $desc
65 65
      * @param  array   $columns
66 66
      * @return collection
67 67
      */
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      * Save the given model to the storage.
77 77
      *
78 78
      * @param  array $data
79
-     * @return mixed
79
+     * @return boolean
80 80
      */
81 81
     public function save(array $data)
82 82
     {
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
      * @param  array   $conditions array of conditions
133 133
      * @param  array   $relations
134 134
      * @param  string  $sortBy
135
-     * @param  boolean $desc
135
+     * @param  integer $desc
136 136
      * @param  array   $columns
137 137
      * @return collection
138 138
      */
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
      * @param  array   $conditions array of conditions
165 165
      * @param  integer $perPage
166 166
      * @param  string  $sortBy
167
-     * @param  boolean $desc
167
+     * @param  integer $desc
168 168
      * @param  array   $columns
169 169
      * @return collection
170 170
      */
Please login to merge, or discard this patch.
Indentation   +595 added lines, -595 removed lines patch added patch discarded remove patch
@@ -8,612 +8,612 @@
 block discarded – undo
8 8
 
9 9
 abstract class BaseRepository implements BaseRepositoryInterface
10 10
 {
11
-    /**
12
-     * @var object
13
-     */
14
-    public $model;
11
+	/**
12
+	 * @var object
13
+	 */
14
+	public $model;
15 15
     
16
-    /**
17
-     * Init new object.
18
-     *
19
-     * @var mixed model
20
-     * @return  void
21
-     */
22
-    public function __construct($model)
23
-    {
24
-        $this->model  = $model;
25
-    }
26
-
27
-    /**
28
-     * Fetch all records with relations from the storage.
29
-     *
30
-     * @param  array   $relations
31
-     * @param  string  $sortBy
32
-     * @param  boolean $desc
33
-     * @param  array   $columns
34
-     * @return collection
35
-     */
36
-    public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
37
-    {
38
-        $sort = $desc ? 'desc' : 'asc';
39
-        return $this->model->with($relations)->orderBy($sortBy, $sort)->get($columns);
40
-    }
16
+	/**
17
+	 * Init new object.
18
+	 *
19
+	 * @var mixed model
20
+	 * @return  void
21
+	 */
22
+	public function __construct($model)
23
+	{
24
+		$this->model  = $model;
25
+	}
26
+
27
+	/**
28
+	 * Fetch all records with relations from the storage.
29
+	 *
30
+	 * @param  array   $relations
31
+	 * @param  string  $sortBy
32
+	 * @param  boolean $desc
33
+	 * @param  array   $columns
34
+	 * @return collection
35
+	 */
36
+	public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
37
+	{
38
+		$sort = $desc ? 'desc' : 'asc';
39
+		return $this->model->with($relations)->orderBy($sortBy, $sort)->get($columns);
40
+	}
41 41
     
42
-    /**
43
-     * Fetch all records with relations from storage in pages.
44
-     *
45
-     * @param  integer $perPage
46
-     * @param  array   $relations
47
-     * @param  string  $sortBy
48
-     * @param  boolean $desc
49
-     * @param  array   $columns
50
-     * @return collection
51
-     */
52
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
53
-    {
54
-        $sort = $desc ? 'desc' : 'asc';
55
-        return $this->model->with($relations)->orderBy($sortBy, $sort)->paginate($perPage, $columns);
56
-    }
57
-
58
-    /**
59
-     * Fetch all records with relations based on
60
-     * the given condition from storage in pages.
61
-     *
62
-     * @param  array   $conditions array of conditions
63
-     * @param  integer $perPage
64
-     * @param  array   $relations
65
-     * @param  string  $sortBy
66
-     * @param  boolean $desc
67
-     * @param  array   $columns
68
-     * @return collection
69
-     */
70
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
71
-    {
72
-        $conditions = $this->constructConditions($conditions, $this->model);
73
-        $sort       = $desc ? 'desc' : 'asc';
74
-        return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns);
75
-    }
76
-
77
-    /**
78
-     * Count all records based on the given condition from storage.
79
-     *
80
-     * @param  array   $conditions array of conditions
81
-     * @return collection
82
-     */
83
-    public function count($conditions = false)
84
-    {
85
-        if($conditions) {
86
-            $conditions = $this->constructConditions($conditions, $this->model);
87
-            return $this->model->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->count();
88
-        }
42
+	/**
43
+	 * Fetch all records with relations from storage in pages.
44
+	 *
45
+	 * @param  integer $perPage
46
+	 * @param  array   $relations
47
+	 * @param  string  $sortBy
48
+	 * @param  boolean $desc
49
+	 * @param  array   $columns
50
+	 * @return collection
51
+	 */
52
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
53
+	{
54
+		$sort = $desc ? 'desc' : 'asc';
55
+		return $this->model->with($relations)->orderBy($sortBy, $sort)->paginate($perPage, $columns);
56
+	}
57
+
58
+	/**
59
+	 * Fetch all records with relations based on
60
+	 * the given condition from storage in pages.
61
+	 *
62
+	 * @param  array   $conditions array of conditions
63
+	 * @param  integer $perPage
64
+	 * @param  array   $relations
65
+	 * @param  string  $sortBy
66
+	 * @param  boolean $desc
67
+	 * @param  array   $columns
68
+	 * @return collection
69
+	 */
70
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
71
+	{
72
+		$conditions = $this->constructConditions($conditions, $this->model);
73
+		$sort       = $desc ? 'desc' : 'asc';
74
+		return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns);
75
+	}
76
+
77
+	/**
78
+	 * Count all records based on the given condition from storage.
79
+	 *
80
+	 * @param  array   $conditions array of conditions
81
+	 * @return collection
82
+	 */
83
+	public function count($conditions = false)
84
+	{
85
+		if($conditions) {
86
+			$conditions = $this->constructConditions($conditions, $this->model);
87
+			return $this->model->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->count();
88
+		}
89 89
         
90
-        return $this->model->count();
91
-    }
92
-
93
-    /**
94
-     * Pluck column based on the given condition from storage.
95
-     *
96
-     * @param  array   $conditions array of conditions
97
-     * @param  string   $column
98
-     * @return collection
99
-     */
100
-    public function pluck($conditions, $column)
101
-    {
102
-        $conditions = $this->constructConditions($conditions, $this->model);
103
-        return $this->model->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->pluck($column);
104
-    }
90
+		return $this->model->count();
91
+	}
92
+
93
+	/**
94
+	 * Pluck column based on the given condition from storage.
95
+	 *
96
+	 * @param  array   $conditions array of conditions
97
+	 * @param  string   $column
98
+	 * @return collection
99
+	 */
100
+	public function pluck($conditions, $column)
101
+	{
102
+		$conditions = $this->constructConditions($conditions, $this->model);
103
+		return $this->model->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->pluck($column);
104
+	}
105 105
     
106
-    /**
107
-     * Save the given model to the storage.
108
-     *
109
-     * @param  array $data
110
-     * @return mixed
111
-     */
112
-    public function save(array $data)
113
-    {
114
-        $local = \Session::get('locale');
115
-        \Session::put('locale', 'all');
116
-        $model      = false;
117
-        $relations  = [];
118
-
119
-        \DB::transaction(function () use (&$model, &$relations, $data) {
106
+	/**
107
+	 * Save the given model to the storage.
108
+	 *
109
+	 * @param  array $data
110
+	 * @return mixed
111
+	 */
112
+	public function save(array $data)
113
+	{
114
+		$local = \Session::get('locale');
115
+		\Session::put('locale', 'all');
116
+		$model      = false;
117
+		$relations  = [];
118
+
119
+		\DB::transaction(function () use (&$model, &$relations, $data) {
120 120
             
121
-            $model     = $this->prepareModel($data);
122
-            $relations = $this->prepareRelations($data, $model);
123
-            $model     = $this->saveModel($model, $relations);
124
-        });
125
-        \Session::put('locale', $local);
121
+			$model     = $this->prepareModel($data);
122
+			$relations = $this->prepareRelations($data, $model);
123
+			$model     = $this->saveModel($model, $relations);
124
+		});
125
+		\Session::put('locale', $local);
126 126
         
127
-        if (count($relations)) {
128
-            $model->load(...array_keys($relations));
129
-        }
127
+		if (count($relations)) {
128
+			$model->load(...array_keys($relations));
129
+		}
130 130
 
131
-        return $model;
132
-    }
131
+		return $model;
132
+	}
133 133
     
134
-    /**
135
-     * Insert the given model/models to the storage.
136
-     *
137
-     * @param  array $data
138
-     * @return mixed
139
-     */
140
-    public function insert(array $data)
141
-    {
142
-        return $this->model->insert($data);
143
-    }
144
-
145
-    /**
146
-     * Delete record from the storage based on the given
147
-     * condition.
148
-     *
149
-     * @param  var $value condition value
150
-     * @param  string $attribute condition column name
151
-     * @return void
152
-     */
153
-    public function delete($value, $attribute = 'id')
154
-    {
155
-        \DB::transaction(function () use ($value, $attribute) {
156
-            $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) {
157
-                $model->delete();
158
-            });
159
-        });
160
-    }
134
+	/**
135
+	 * Insert the given model/models to the storage.
136
+	 *
137
+	 * @param  array $data
138
+	 * @return mixed
139
+	 */
140
+	public function insert(array $data)
141
+	{
142
+		return $this->model->insert($data);
143
+	}
144
+
145
+	/**
146
+	 * Delete record from the storage based on the given
147
+	 * condition.
148
+	 *
149
+	 * @param  var $value condition value
150
+	 * @param  string $attribute condition column name
151
+	 * @return void
152
+	 */
153
+	public function delete($value, $attribute = 'id')
154
+	{
155
+		\DB::transaction(function () use ($value, $attribute) {
156
+			$this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) {
157
+				$model->delete();
158
+			});
159
+		});
160
+	}
161 161
     
162
-    /**
163
-     * Fetch records from the storage based on the given
164
-     * id.
165
-     *
166
-     * @param  integer $id
167
-     * @param  string[]   $relations
168
-     * @param  array   $columns
169
-     * @return object
170
-     */
171
-    public function find($id, $relations = [], $columns = ['*'])
172
-    {
173
-        return $this->model->with($relations)->find($id, $columns);
174
-    }
162
+	/**
163
+	 * Fetch records from the storage based on the given
164
+	 * id.
165
+	 *
166
+	 * @param  integer $id
167
+	 * @param  string[]   $relations
168
+	 * @param  array   $columns
169
+	 * @return object
170
+	 */
171
+	public function find($id, $relations = [], $columns = ['*'])
172
+	{
173
+		return $this->model->with($relations)->find($id, $columns);
174
+	}
175 175
     
176
-    /**
177
-     * Fetch records from the storage based on the given
178
-     * condition.
179
-     *
180
-     * @param  array   $conditions array of conditions
181
-     * @param  array   $relations
182
-     * @param  string  $sortBy
183
-     * @param  boolean $desc
184
-     * @param  array   $columns
185
-     * @return collection
186
-     */
187
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
188
-    {
189
-        $conditions = $this->constructConditions($conditions, $this->model);
190
-        $sort       = $desc ? 'desc' : 'asc';
191
-        return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
192
-    }
193
-
194
-    /**
195
-     * Fetch the first record from the storage based on the given
196
-     * condition.
197
-     *
198
-     * @param  array   $conditions array of conditions
199
-     * @param  array   $relations
200
-     * @param  array   $columns
201
-     * @return object
202
-     */
203
-    public function first($conditions, $relations = [], $columns = ['*'])
204
-    {
205
-        $conditions = $this->constructConditions($conditions, $this->model);
206
-        return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);
207
-    }
208
-
209
-    /**
210
-     * Return the deleted models in pages based on the given conditions.
211
-     *
212
-     * @param  array   $conditions array of conditions
213
-     * @param  integer $perPage
214
-     * @param  string  $sortBy
215
-     * @param  boolean $desc
216
-     * @param  array   $columns
217
-     * @return collection
218
-     */
219
-    public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*'])
220
-    {
221
-        unset($conditions['page']);
222
-        unset($conditions['perPage']);
223
-        unset($conditions['sortBy']);
224
-        unset($conditions['sort']);
225
-        $conditions = $this->constructConditions($conditions, $this->model);
226
-        $sort       = $desc ? 'desc' : 'asc';
227
-        $model      = $this->model->onlyTrashed();
228
-
229
-        if (count($conditions['conditionValues'])) {
230
-            $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
231
-        }
232
-
233
-        return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
234
-    }
235
-
236
-    /**
237
-     * Restore the deleted model.
238
-     *
239
-     * @param  integer $id
240
-     * @return void
241
-     */
242
-    public function restore($id)
243
-    {
244
-        $model = $this->model->onlyTrashed()->find($id);
245
-
246
-        if (! $model) {
247
-            \Errors::notFound(class_basename($this->model).' with id : '.$id);
248
-        }
249
-
250
-        $model->restore();
251
-    }
252
-
253
-    /**
254
-     * Fill the model with the given data.
255
-     *
256
-     * @param   array  $data
257
-     *
258
-     * @return  object
259
-     */
260
-    public function prepareModel($data)
261
-    {
262
-        $modelClass = $this->model;
263
-
264
-        /**
265
-         * If the id is present in the data then select the model for updating,
266
-         * else create new model.
267
-         * @var array
268
-         */
269
-        $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
270
-        if (! $model) {
271
-            \Errors::notFound(class_basename($modelClass).' with id : '.$data['id']);
272
-        }
273
-
274
-        /**
275
-         * Construct the model object with the given data,
276
-         * and if there is a relation add it to relations array,
277
-         * then save the model.
278
-         */
279
-        foreach ($data as $key => $value) {
280
-            if (array_search($key, $model->getFillable(), true) !== false) {
281
-                /**
282
-                 * If the attribute isn't a relation and prevent attributes not in the fillable.
283
-                 */
284
-                $model->$key = $value;
285
-            }
286
-        }
287
-
288
-        return $model;
289
-    }
176
+	/**
177
+	 * Fetch records from the storage based on the given
178
+	 * condition.
179
+	 *
180
+	 * @param  array   $conditions array of conditions
181
+	 * @param  array   $relations
182
+	 * @param  string  $sortBy
183
+	 * @param  boolean $desc
184
+	 * @param  array   $columns
185
+	 * @return collection
186
+	 */
187
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
188
+	{
189
+		$conditions = $this->constructConditions($conditions, $this->model);
190
+		$sort       = $desc ? 'desc' : 'asc';
191
+		return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
192
+	}
193
+
194
+	/**
195
+	 * Fetch the first record from the storage based on the given
196
+	 * condition.
197
+	 *
198
+	 * @param  array   $conditions array of conditions
199
+	 * @param  array   $relations
200
+	 * @param  array   $columns
201
+	 * @return object
202
+	 */
203
+	public function first($conditions, $relations = [], $columns = ['*'])
204
+	{
205
+		$conditions = $this->constructConditions($conditions, $this->model);
206
+		return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);
207
+	}
208
+
209
+	/**
210
+	 * Return the deleted models in pages based on the given conditions.
211
+	 *
212
+	 * @param  array   $conditions array of conditions
213
+	 * @param  integer $perPage
214
+	 * @param  string  $sortBy
215
+	 * @param  boolean $desc
216
+	 * @param  array   $columns
217
+	 * @return collection
218
+	 */
219
+	public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*'])
220
+	{
221
+		unset($conditions['page']);
222
+		unset($conditions['perPage']);
223
+		unset($conditions['sortBy']);
224
+		unset($conditions['sort']);
225
+		$conditions = $this->constructConditions($conditions, $this->model);
226
+		$sort       = $desc ? 'desc' : 'asc';
227
+		$model      = $this->model->onlyTrashed();
228
+
229
+		if (count($conditions['conditionValues'])) {
230
+			$model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
231
+		}
232
+
233
+		return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
234
+	}
235
+
236
+	/**
237
+	 * Restore the deleted model.
238
+	 *
239
+	 * @param  integer $id
240
+	 * @return void
241
+	 */
242
+	public function restore($id)
243
+	{
244
+		$model = $this->model->onlyTrashed()->find($id);
245
+
246
+		if (! $model) {
247
+			\Errors::notFound(class_basename($this->model).' with id : '.$id);
248
+		}
249
+
250
+		$model->restore();
251
+	}
252
+
253
+	/**
254
+	 * Fill the model with the given data.
255
+	 *
256
+	 * @param   array  $data
257
+	 *
258
+	 * @return  object
259
+	 */
260
+	public function prepareModel($data)
261
+	{
262
+		$modelClass = $this->model;
263
+
264
+		/**
265
+		 * If the id is present in the data then select the model for updating,
266
+		 * else create new model.
267
+		 * @var array
268
+		 */
269
+		$model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
270
+		if (! $model) {
271
+			\Errors::notFound(class_basename($modelClass).' with id : '.$data['id']);
272
+		}
273
+
274
+		/**
275
+		 * Construct the model object with the given data,
276
+		 * and if there is a relation add it to relations array,
277
+		 * then save the model.
278
+		 */
279
+		foreach ($data as $key => $value) {
280
+			if (array_search($key, $model->getFillable(), true) !== false) {
281
+				/**
282
+				 * If the attribute isn't a relation and prevent attributes not in the fillable.
283
+				 */
284
+				$model->$key = $value;
285
+			}
286
+		}
287
+
288
+		return $model;
289
+	}
290 290
     
291
-    /**
292
-     * Prepare related models based on the given data for the given model.
293
-     *
294
-     * @param   array  $data
295
-     * @param   object $model
296
-     *
297
-     * @return  array
298
-     */
299
-    public function prepareRelations($data, $model)
300
-    {
301
-        /**
302
-         * Init the relation array
303
-         *
304
-         * @var array
305
-         */
306
-        $relations = [];
307
-
308
-        /**
309
-         * Construct the model object with the given data,
310
-         * and if there is a relation add it to relations array,
311
-         * then save the model.
312
-         */
313
-        foreach ($data as $key => $value) {
314
-            /**
315
-             * If the attribute is a relation.
316
-             */
317
-            $relation = \Str::camel($key);
318
-            if (method_exists($model, $relation) && \Core::$relation()) {
319
-                /**
320
-                 * Check if the relation is a collection.
321
-                 */
322
-                if (class_basename($model->$relation) == 'Collection') {
323
-                    /**
324
-                     * If the relation has no value then marke the relation data
325
-                     * related to the model to be deleted.
326
-                     */
327
-                    if (! $value || ! count($value)) {
328
-                        $relations[$relation] = 'delete';
329
-                    }
330
-                }
331
-                if (is_array($value)) {
332
-                    /**
333
-                     * Loop through the relation data.
334
-                     */
335
-                    foreach ($value as $attr => $val) {
336
-                        /**
337
-                         * Get the relation model.
338
-                         */
339
-                        $relationBaseModel = \Core::$relation()->model;
340
-
341
-                        /**
342
-                         * Check if the relation is a collection.
343
-                         */
344
-                        if (class_basename($model->$relation) == 'Collection') {
345
-                            if (! is_array($val)) {
346
-                                $relationModel = $relationBaseModel->lockForUpdate()->find($val);
347
-                            } else {
348
-                                /**
349
-                                 * If the id is present in the data then select the relation model for updating,
350
-                                 * else create new model.
351
-                                 */
352
-                                $relationModel = Arr::has($val, 'id') ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel;
353
-                            }
354
-
355
-                            /**
356
-                             * If model doesn't exists.
357
-                             */
358
-                            if (! $relationModel) {
359
-                                \Errors::notFound(class_basename($relationBaseModel).' with id : '.$val['id']);
360
-                            }
361
-
362
-                            if (is_array($val)) {
363
-                                /**
364
-                                 * Loop through the relation attributes.
365
-                                 */
366
-                                foreach ($val as $attr => $val) {
367
-                                    /**
368
-                                     * Prevent the sub relations or attributes not in the fillable.
369
-                                     */
370
-                                    if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false && class_basename($model->$key()) !== 'BelongsToMany') {
371
-                                        $relationModel->$attr = $val;
372
-                                    } elseif (gettype($val) !== 'object' && gettype($val) !== 'array' && $attr !== 'id') {
373
-                                        $extra[$attr] = $val;
374
-                                    }
375
-                                }
376
-                            }
377
-
378
-                            if (isset($extra)) {
379
-                                $relationModel->extra = $extra;
380
-                            }
381
-                            $relations[$relation][] = $relationModel;
382
-                        } else {
383
-                            /**
384
-                             * Prevent the sub relations.
385
-                             */
386
-                            if (gettype($val) !== 'object' && gettype($val) !== 'array') {
387
-                                /**
388
-                                 * If the id is present in the data then select the relation model for updating,
389
-                                 * else create new model.
390
-                                 */
391
-                                $relationModel = Arr::has($value, 'id') ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel;
392
-
393
-                                /**
394
-                                 * If model doesn't exists.
395
-                                 */
396
-                                if (! $relationModel) {
397
-                                    \Errors::notFound(class_basename($relationBaseModel).' with id : '.$value['id']);
398
-                                }
399
-
400
-                                foreach ($value as $relationAttribute => $relationValue) {
401
-                                    /**
402
-                                     * Prevent attributes not in the fillable.
403
-                                     */
404
-                                    if (array_search($relationAttribute, $relationModel->getFillable(), true) !== false) {
405
-                                        $relationModel->$relationAttribute = $relationValue;
406
-                                    }
407
-                                }
408
-
409
-                                $relations[$relation] = $relationModel;
410
-                            }
411
-                        }
412
-                    }
413
-                }
414
-            }
415
-        }
416
-
417
-        return $relations;
418
-    }
419
-
420
-    /**
421
-     * Save the model with related models.
422
-     *
423
-     * @param   object  $model
424
-     * @param   array   $relations
425
-     *
426
-     * @return  object
427
-     */
428
-    public function saveModel($model, $relations)
429
-    {
430
-
431
-        /**
432
-         * Loop through the relations array.
433
-         */
434
-        foreach ($relations as $key => $value) {
435
-            /**
436
-             * If the relation is marked for delete then delete it.
437
-             */
438
-            if ($value == 'delete' && $model->$key()->count()) {
439
-                $model->$key()->delete();
440
-            } elseif (gettype($value) == 'array') {
441
-                /**
442
-                 * Save the model.
443
-                 */
444
-                $model->save();
445
-                $ids = [];
446
-
447
-                /**
448
-                 * Loop through the relations.
449
-                 */
450
-                foreach ($value as $val) {
451
-                    switch (class_basename($model->$key())) {
452
-                        /**
453
-                         * If the relation is one to many then update it's foreign key with
454
-                         * the model id and save it then add its id to ids array to delete all
455
-                         * relations who's id isn't in the ids array.
456
-                         */
457
-                        case 'HasMany':
458
-                            $foreignKeyName       = $model->$key()->getForeignKeyName();
459
-                            $val->$foreignKeyName = $model->id;
460
-                            $val->save();
461
-                            $ids[] = $val->id;
462
-                            break;
463
-
464
-                        /**
465
-                         * If the relation is many to many then add it's id to the ids array to
466
-                         * attache these ids to the model.
467
-                         */
468
-                        case 'BelongsToMany':
469
-                        case 'MorphToMany':
470
-                            $extra = $val->extra;
471
-                            unset($val->extra);
472
-                            $val->save();
473
-                            $ids[$val->id] = $extra ?? [];
474
-                            break;
475
-                    }
476
-                }
477
-                switch (class_basename($model->$key())) {
478
-                    /**
479
-                     * If the relation is one to many then delete all
480
-                     * relations who's id isn't in the ids array.
481
-                     */
482
-                    case 'HasMany':
483
-                        $model->$key()->whereNotIn('id', $ids)->delete();
484
-                        break;
485
-
486
-                    /**
487
-                     * If the relation is many to many then
488
-                     * detach the previous data and attach
489
-                     * the ids array to the model.
490
-                     */
491
-                    case 'BelongsToMany':
492
-                    case 'MorphToMany':
493
-                        $model->$key()->detach();
494
-                        $model->$key()->attach($ids);
495
-                        break;
496
-                }
497
-            } else {
498
-                switch (class_basename($model->$key())) {
499
-                    /**
500
-                     * If the relation is one to one.
501
-                     */
502
-                    case 'HasOne':
503
-                        /**
504
-                         * Save the model.
505
-                         */
506
-                        $model->save();
507
-                        $foreignKeyName         = $model->$key()->getForeignKeyName();
508
-                        $value->$foreignKeyName = $model->id;
509
-                        $value->save();
510
-                        break;
511
-                    case 'BelongsTo':
512
-                        /**
513
-                         * Save the model.
514
-                         */
515
-                        $value->save();
516
-                        $model->$key()->associate($value);
517
-                        break;
518
-                }
519
-            }
520
-        }
521
-
522
-        /**
523
-         * Save the model.
524
-         */
525
-        $model->save();
526
-
527
-        return $model;
528
-    }
529
-
530
-    /**
531
-     * Build the conditions recursively for the retrieving methods.
532
-     * @param  array $conditions
533
-     * @return array
534
-     */
535
-    protected function constructConditions($conditions, $model)
536
-    {
537
-        $conditionString = '';
538
-        $conditionValues = [];
539
-        foreach ($conditions as $key => $value) {
540
-            if (Str::contains($key, '->')) {
541
-                $key = $this->wrapJsonSelector($key);
542
-            }
543
-
544
-            if ($key == 'and') {
545
-                $conditions       = $this->constructConditions($value, $model);
546
-                $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} ';
547
-                $conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
548
-            } elseif ($key == 'or') {
549
-                $conditions       = $this->constructConditions($value, $model);
550
-                $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} ';
551
-                $conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
552
-            } else {
553
-                if (is_array($value)) {
554
-                    $operator = $value['op'];
555
-                    if (strtolower($operator) == 'between') {
556
-                        $value1 = $value['val1'];
557
-                        $value2 = $value['val2'];
558
-                    } else {
559
-                        $value = Arr::get($value, 'val', '');
560
-                    }
561
-                } else {
562
-                    $operator = '=';
563
-                }
291
+	/**
292
+	 * Prepare related models based on the given data for the given model.
293
+	 *
294
+	 * @param   array  $data
295
+	 * @param   object $model
296
+	 *
297
+	 * @return  array
298
+	 */
299
+	public function prepareRelations($data, $model)
300
+	{
301
+		/**
302
+		 * Init the relation array
303
+		 *
304
+		 * @var array
305
+		 */
306
+		$relations = [];
307
+
308
+		/**
309
+		 * Construct the model object with the given data,
310
+		 * and if there is a relation add it to relations array,
311
+		 * then save the model.
312
+		 */
313
+		foreach ($data as $key => $value) {
314
+			/**
315
+			 * If the attribute is a relation.
316
+			 */
317
+			$relation = \Str::camel($key);
318
+			if (method_exists($model, $relation) && \Core::$relation()) {
319
+				/**
320
+				 * Check if the relation is a collection.
321
+				 */
322
+				if (class_basename($model->$relation) == 'Collection') {
323
+					/**
324
+					 * If the relation has no value then marke the relation data
325
+					 * related to the model to be deleted.
326
+					 */
327
+					if (! $value || ! count($value)) {
328
+						$relations[$relation] = 'delete';
329
+					}
330
+				}
331
+				if (is_array($value)) {
332
+					/**
333
+					 * Loop through the relation data.
334
+					 */
335
+					foreach ($value as $attr => $val) {
336
+						/**
337
+						 * Get the relation model.
338
+						 */
339
+						$relationBaseModel = \Core::$relation()->model;
340
+
341
+						/**
342
+						 * Check if the relation is a collection.
343
+						 */
344
+						if (class_basename($model->$relation) == 'Collection') {
345
+							if (! is_array($val)) {
346
+								$relationModel = $relationBaseModel->lockForUpdate()->find($val);
347
+							} else {
348
+								/**
349
+								 * If the id is present in the data then select the relation model for updating,
350
+								 * else create new model.
351
+								 */
352
+								$relationModel = Arr::has($val, 'id') ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel;
353
+							}
354
+
355
+							/**
356
+							 * If model doesn't exists.
357
+							 */
358
+							if (! $relationModel) {
359
+								\Errors::notFound(class_basename($relationBaseModel).' with id : '.$val['id']);
360
+							}
361
+
362
+							if (is_array($val)) {
363
+								/**
364
+								 * Loop through the relation attributes.
365
+								 */
366
+								foreach ($val as $attr => $val) {
367
+									/**
368
+									 * Prevent the sub relations or attributes not in the fillable.
369
+									 */
370
+									if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false && class_basename($model->$key()) !== 'BelongsToMany') {
371
+										$relationModel->$attr = $val;
372
+									} elseif (gettype($val) !== 'object' && gettype($val) !== 'array' && $attr !== 'id') {
373
+										$extra[$attr] = $val;
374
+									}
375
+								}
376
+							}
377
+
378
+							if (isset($extra)) {
379
+								$relationModel->extra = $extra;
380
+							}
381
+							$relations[$relation][] = $relationModel;
382
+						} else {
383
+							/**
384
+							 * Prevent the sub relations.
385
+							 */
386
+							if (gettype($val) !== 'object' && gettype($val) !== 'array') {
387
+								/**
388
+								 * If the id is present in the data then select the relation model for updating,
389
+								 * else create new model.
390
+								 */
391
+								$relationModel = Arr::has($value, 'id') ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel;
392
+
393
+								/**
394
+								 * If model doesn't exists.
395
+								 */
396
+								if (! $relationModel) {
397
+									\Errors::notFound(class_basename($relationBaseModel).' with id : '.$value['id']);
398
+								}
399
+
400
+								foreach ($value as $relationAttribute => $relationValue) {
401
+									/**
402
+									 * Prevent attributes not in the fillable.
403
+									 */
404
+									if (array_search($relationAttribute, $relationModel->getFillable(), true) !== false) {
405
+										$relationModel->$relationAttribute = $relationValue;
406
+									}
407
+								}
408
+
409
+								$relations[$relation] = $relationModel;
410
+							}
411
+						}
412
+					}
413
+				}
414
+			}
415
+		}
416
+
417
+		return $relations;
418
+	}
419
+
420
+	/**
421
+	 * Save the model with related models.
422
+	 *
423
+	 * @param   object  $model
424
+	 * @param   array   $relations
425
+	 *
426
+	 * @return  object
427
+	 */
428
+	public function saveModel($model, $relations)
429
+	{
430
+
431
+		/**
432
+		 * Loop through the relations array.
433
+		 */
434
+		foreach ($relations as $key => $value) {
435
+			/**
436
+			 * If the relation is marked for delete then delete it.
437
+			 */
438
+			if ($value == 'delete' && $model->$key()->count()) {
439
+				$model->$key()->delete();
440
+			} elseif (gettype($value) == 'array') {
441
+				/**
442
+				 * Save the model.
443
+				 */
444
+				$model->save();
445
+				$ids = [];
446
+
447
+				/**
448
+				 * Loop through the relations.
449
+				 */
450
+				foreach ($value as $val) {
451
+					switch (class_basename($model->$key())) {
452
+						/**
453
+						 * If the relation is one to many then update it's foreign key with
454
+						 * the model id and save it then add its id to ids array to delete all
455
+						 * relations who's id isn't in the ids array.
456
+						 */
457
+						case 'HasMany':
458
+							$foreignKeyName       = $model->$key()->getForeignKeyName();
459
+							$val->$foreignKeyName = $model->id;
460
+							$val->save();
461
+							$ids[] = $val->id;
462
+							break;
463
+
464
+						/**
465
+						 * If the relation is many to many then add it's id to the ids array to
466
+						 * attache these ids to the model.
467
+						 */
468
+						case 'BelongsToMany':
469
+						case 'MorphToMany':
470
+							$extra = $val->extra;
471
+							unset($val->extra);
472
+							$val->save();
473
+							$ids[$val->id] = $extra ?? [];
474
+							break;
475
+					}
476
+				}
477
+				switch (class_basename($model->$key())) {
478
+					/**
479
+					 * If the relation is one to many then delete all
480
+					 * relations who's id isn't in the ids array.
481
+					 */
482
+					case 'HasMany':
483
+						$model->$key()->whereNotIn('id', $ids)->delete();
484
+						break;
485
+
486
+					/**
487
+					 * If the relation is many to many then
488
+					 * detach the previous data and attach
489
+					 * the ids array to the model.
490
+					 */
491
+					case 'BelongsToMany':
492
+					case 'MorphToMany':
493
+						$model->$key()->detach();
494
+						$model->$key()->attach($ids);
495
+						break;
496
+				}
497
+			} else {
498
+				switch (class_basename($model->$key())) {
499
+					/**
500
+					 * If the relation is one to one.
501
+					 */
502
+					case 'HasOne':
503
+						/**
504
+						 * Save the model.
505
+						 */
506
+						$model->save();
507
+						$foreignKeyName         = $model->$key()->getForeignKeyName();
508
+						$value->$foreignKeyName = $model->id;
509
+						$value->save();
510
+						break;
511
+					case 'BelongsTo':
512
+						/**
513
+						 * Save the model.
514
+						 */
515
+						$value->save();
516
+						$model->$key()->associate($value);
517
+						break;
518
+				}
519
+			}
520
+		}
521
+
522
+		/**
523
+		 * Save the model.
524
+		 */
525
+		$model->save();
526
+
527
+		return $model;
528
+	}
529
+
530
+	/**
531
+	 * Build the conditions recursively for the retrieving methods.
532
+	 * @param  array $conditions
533
+	 * @return array
534
+	 */
535
+	protected function constructConditions($conditions, $model)
536
+	{
537
+		$conditionString = '';
538
+		$conditionValues = [];
539
+		foreach ($conditions as $key => $value) {
540
+			if (Str::contains($key, '->')) {
541
+				$key = $this->wrapJsonSelector($key);
542
+			}
543
+
544
+			if ($key == 'and') {
545
+				$conditions       = $this->constructConditions($value, $model);
546
+				$conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} ';
547
+				$conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
548
+			} elseif ($key == 'or') {
549
+				$conditions       = $this->constructConditions($value, $model);
550
+				$conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} ';
551
+				$conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
552
+			} else {
553
+				if (is_array($value)) {
554
+					$operator = $value['op'];
555
+					if (strtolower($operator) == 'between') {
556
+						$value1 = $value['val1'];
557
+						$value2 = $value['val2'];
558
+					} else {
559
+						$value = Arr::get($value, 'val', '');
560
+					}
561
+				} else {
562
+					$operator = '=';
563
+				}
564 564
                 
565
-                if (strtolower($operator) == 'between') {
566
-                    $conditionString  .= $key.' >= ? and ';
567
-                    $conditionValues[] = $value1;
568
-
569
-                    $conditionString  .= $key.' <= ? {op} ';
570
-                    $conditionValues[] = $value2;
571
-                } elseif (strtolower($operator) == 'in') {
572
-                    $conditionValues  = array_merge($conditionValues, $value);
573
-                    $inBindingsString = rtrim(str_repeat('?,', count($value)), ',');
574
-                    $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} ';
575
-                } elseif (strtolower($operator) == 'null') {
576
-                    $conditionString .= $key.' is null {op} ';
577
-                } elseif (strtolower($operator) == 'not null') {
578
-                    $conditionString .= $key.' is not null {op} ';
579
-                } elseif (strtolower($operator) == 'has') {
580
-                    $sql              = $model->withTrashed()->withoutGlobalScopes()->has($key)->toSql();
581
-                    $bindings         = $model->withTrashed()->withoutGlobalScopes()->has($key)->getBindings();
582
-                    if($value) {
583
-                        $conditions       = $this->constructConditions($value, $model->$key()->getRelated());
584
-                        $conditionString .= substr(substr($sql, strpos($sql, 'exists')), 0, -1).' and '.$conditions['conditionString'].') {op} ';
585
-                        $conditionValues  = array_merge($conditionValues, $bindings);
586
-                        $conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
587
-                    } else {
588
-                        $conditionString .= substr(substr($sql, strpos($sql, 'exists')), 0, -1).') {op} ';
589
-                        $conditionValues  = array_merge($conditionValues, $bindings);
590
-                    }
591
-                } else {
592
-                    $conditionString  .= $key.' '.$operator.' ? {op} ';
593
-                    $conditionValues[] = $value;
594
-                }
595
-            }
596
-        }
597
-        $conditionString = '('.rtrim($conditionString, '{op} ').')';
598
-        return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
599
-    }
600
-
601
-    /**
602
-     * Wrap the given JSON selector.
603
-     *
604
-     * @param  string  $value
605
-     * @return string
606
-     */
607
-    protected function wrapJsonSelector($value)
608
-    {
609
-        $removeLast = strpos($value, ')');
610
-        $value      = $removeLast === false ? $value : substr($value, 0, $removeLast);
611
-        $path       = explode('->', $value);
612
-        $field      = array_shift($path);
613
-        $result     = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) {
614
-            return '"'.$part.'"';
615
-        })->implode('.'));
565
+				if (strtolower($operator) == 'between') {
566
+					$conditionString  .= $key.' >= ? and ';
567
+					$conditionValues[] = $value1;
568
+
569
+					$conditionString  .= $key.' <= ? {op} ';
570
+					$conditionValues[] = $value2;
571
+				} elseif (strtolower($operator) == 'in') {
572
+					$conditionValues  = array_merge($conditionValues, $value);
573
+					$inBindingsString = rtrim(str_repeat('?,', count($value)), ',');
574
+					$conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} ';
575
+				} elseif (strtolower($operator) == 'null') {
576
+					$conditionString .= $key.' is null {op} ';
577
+				} elseif (strtolower($operator) == 'not null') {
578
+					$conditionString .= $key.' is not null {op} ';
579
+				} elseif (strtolower($operator) == 'has') {
580
+					$sql              = $model->withTrashed()->withoutGlobalScopes()->has($key)->toSql();
581
+					$bindings         = $model->withTrashed()->withoutGlobalScopes()->has($key)->getBindings();
582
+					if($value) {
583
+						$conditions       = $this->constructConditions($value, $model->$key()->getRelated());
584
+						$conditionString .= substr(substr($sql, strpos($sql, 'exists')), 0, -1).' and '.$conditions['conditionString'].') {op} ';
585
+						$conditionValues  = array_merge($conditionValues, $bindings);
586
+						$conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
587
+					} else {
588
+						$conditionString .= substr(substr($sql, strpos($sql, 'exists')), 0, -1).') {op} ';
589
+						$conditionValues  = array_merge($conditionValues, $bindings);
590
+					}
591
+				} else {
592
+					$conditionString  .= $key.' '.$operator.' ? {op} ';
593
+					$conditionValues[] = $value;
594
+				}
595
+			}
596
+		}
597
+		$conditionString = '('.rtrim($conditionString, '{op} ').')';
598
+		return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
599
+	}
600
+
601
+	/**
602
+	 * Wrap the given JSON selector.
603
+	 *
604
+	 * @param  string  $value
605
+	 * @return string
606
+	 */
607
+	protected function wrapJsonSelector($value)
608
+	{
609
+		$removeLast = strpos($value, ')');
610
+		$value      = $removeLast === false ? $value : substr($value, 0, $removeLast);
611
+		$path       = explode('->', $value);
612
+		$field      = array_shift($path);
613
+		$result     = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) {
614
+			return '"'.$part.'"';
615
+		})->implode('.'));
616 616
         
617
-        return $removeLast === false ? $result : $result.')';
618
-    }
617
+		return $removeLast === false ? $result : $result.')';
618
+	}
619 619
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
      */
22 22
     public function __construct($model)
23 23
     {
24
-        $this->model  = $model;
24
+        $this->model = $model;
25 25
     }
26 26
 
27 27
     /**
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function count($conditions = false)
84 84
     {
85
-        if($conditions) {
85
+        if ($conditions) {
86 86
             $conditions = $this->constructConditions($conditions, $this->model);
87 87
             return $this->model->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->count();
88 88
         }
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
         $model      = false;
117 117
         $relations  = [];
118 118
 
119
-        \DB::transaction(function () use (&$model, &$relations, $data) {
119
+        \DB::transaction(function() use (&$model, &$relations, $data) {
120 120
             
121 121
             $model     = $this->prepareModel($data);
122 122
             $relations = $this->prepareRelations($data, $model);
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
      */
153 153
     public function delete($value, $attribute = 'id')
154 154
     {
155
-        \DB::transaction(function () use ($value, $attribute) {
156
-            $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) {
155
+        \DB::transaction(function() use ($value, $attribute) {
156
+            $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function($model) {
157 157
                 $model->delete();
158 158
             });
159 159
         });
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
     {
244 244
         $model = $this->model->onlyTrashed()->find($id);
245 245
 
246
-        if (! $model) {
246
+        if ( ! $model) {
247 247
             \Errors::notFound(class_basename($this->model).' with id : '.$id);
248 248
         }
249 249
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
          * @var array
268 268
          */
269 269
         $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
270
-        if (! $model) {
270
+        if ( ! $model) {
271 271
             \Errors::notFound(class_basename($modelClass).' with id : '.$data['id']);
272 272
         }
273 273
 
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
                      * If the relation has no value then marke the relation data
325 325
                      * related to the model to be deleted.
326 326
                      */
327
-                    if (! $value || ! count($value)) {
327
+                    if ( ! $value || ! count($value)) {
328 328
                         $relations[$relation] = 'delete';
329 329
                     }
330 330
                 }
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
                          * Check if the relation is a collection.
343 343
                          */
344 344
                         if (class_basename($model->$relation) == 'Collection') {
345
-                            if (! is_array($val)) {
345
+                            if ( ! is_array($val)) {
346 346
                                 $relationModel = $relationBaseModel->lockForUpdate()->find($val);
347 347
                             } else {
348 348
                                 /**
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
                             /**
356 356
                              * If model doesn't exists.
357 357
                              */
358
-                            if (! $relationModel) {
358
+                            if ( ! $relationModel) {
359 359
                                 \Errors::notFound(class_basename($relationBaseModel).' with id : '.$val['id']);
360 360
                             }
361 361
 
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
                                 /**
394 394
                                  * If model doesn't exists.
395 395
                                  */
396
-                                if (! $relationModel) {
396
+                                if ( ! $relationModel) {
397 397
                                     \Errors::notFound(class_basename($relationBaseModel).' with id : '.$value['id']);
398 398
                                 }
399 399
 
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
                 } elseif (strtolower($operator) == 'has') {
580 580
                     $sql              = $model->withTrashed()->withoutGlobalScopes()->has($key)->toSql();
581 581
                     $bindings         = $model->withTrashed()->withoutGlobalScopes()->has($key)->getBindings();
582
-                    if($value) {
582
+                    if ($value) {
583 583
                         $conditions       = $this->constructConditions($value, $model->$key()->getRelated());
584 584
                         $conditionString .= substr(substr($sql, strpos($sql, 'exists')), 0, -1).' and '.$conditions['conditionString'].') {op} ';
585 585
                         $conditionValues  = array_merge($conditionValues, $bindings);
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
         $value      = $removeLast === false ? $value : substr($value, 0, $removeLast);
611 611
         $path       = explode('->', $value);
612 612
         $field      = array_shift($path);
613
-        $result     = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) {
613
+        $result     = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function($part) {
614 614
             return '"'.$part.'"';
615 615
         })->implode('.'));
616 616
         
Please login to merge, or discard this patch.
src/Modules/Core/BaseClasses/BaseService.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @param  array   $relations
54 54
      * @param  string  $sortBy
55
-     * @param  boolean $desc
55
+     * @param  integer $desc
56 56
      * @param  array   $columns
57 57
      * @return collection
58 58
      */
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      * @param  integer $perPage
68 68
      * @param  array   $relations
69 69
      * @param  string  $sortBy
70
-     * @param  boolean $desc
70
+     * @param  integer $desc
71 71
      * @param  array   $columns
72 72
      * @return collection
73 73
      */
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      * @param  integer $perPage
85 85
      * @param  array   $relations
86 86
      * @param  string  $sortBy
87
-     * @param  boolean $desc
87
+     * @param  integer $desc
88 88
      * @param  array   $columns
89 89
      * @return collection
90 90
      */
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      * @param  array   $conditions array of conditions
139 139
      * @param  array   $relations
140 140
      * @param  string  $sortBy
141
-     * @param  boolean $desc
141
+     * @param  integer $desc
142 142
      * @param  array   $columns
143 143
      * @return collection
144 144
      */
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
      * @param  array   $conditions array of conditions
168 168
      * @param  integer $perPage
169 169
      * @param  string  $sortBy
170
-     * @param  boolean $desc
170
+     * @param  integer $desc
171 171
      * @param  array   $columns
172 172
      * @return collection
173 173
      */
Please login to merge, or discard this patch.
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -7,250 +7,250 @@
 block discarded – undo
7 7
 
8 8
 abstract class BaseService implements BaseServiceInterface
9 9
 {
10
-    /**
11
-     * @var object
12
-     */
13
-    public $repo;
10
+	/**
11
+	 * @var object
12
+	 */
13
+	public $repo;
14 14
 
15
-    /**
16
-     * Init new object.
17
-     *
18
-     * @param   mixed  $repo
19
-     * @return  void
20
-     */
21
-    public function __construct($repo)
22
-    {
23
-        $this->repo = $repo;
24
-    }
15
+	/**
16
+	 * Init new object.
17
+	 *
18
+	 * @param   mixed  $repo
19
+	 * @return  void
20
+	 */
21
+	public function __construct($repo)
22
+	{
23
+		$this->repo = $repo;
24
+	}
25 25
 
26
-    /**
27
-     * Fetch records with relations based on the given params.
28
-     *
29
-     * @param   array   $relations
30
-     * @param   array   $conditions
31
-     * @param   integer $perPage
32
-     * @param   string  $sortBy
33
-     * @param   boolean $desc
34
-     * @param   boolean $trashed
35
-     * @return collection
36
-     */
37
-    public function list($relations = [], $conditions = false, $perPage = 15, $sortBy = 'created_at', $desc = true, $trashed = false)
38
-    {
39
-        $translatable = $this->repo->model->translatable ?? [];
40
-        $filters = $this->constructFilters($conditions);
41
-        $sortBy = in_array($sortBy, $translatable) ? $sortBy . '->' . Session::get('locale') : $sortBy;
26
+	/**
27
+	 * Fetch records with relations based on the given params.
28
+	 *
29
+	 * @param   array   $relations
30
+	 * @param   array   $conditions
31
+	 * @param   integer $perPage
32
+	 * @param   string  $sortBy
33
+	 * @param   boolean $desc
34
+	 * @param   boolean $trashed
35
+	 * @return collection
36
+	 */
37
+	public function list($relations = [], $conditions = false, $perPage = 15, $sortBy = 'created_at', $desc = true, $trashed = false)
38
+	{
39
+		$translatable = $this->repo->model->translatable ?? [];
40
+		$filters = $this->constructFilters($conditions);
41
+		$sortBy = in_array($sortBy, $translatable) ? $sortBy . '->' . Session::get('locale') : $sortBy;
42 42
 
43
-        if ($trashed) {
44
-            return $this->deleted(['and' => $filters], $perPage ?? 15, $sortBy ?? 'created_at', $desc ?? true);
45
-        }
43
+		if ($trashed) {
44
+			return $this->deleted(['and' => $filters], $perPage ?? 15, $sortBy ?? 'created_at', $desc ?? true);
45
+		}
46 46
         
47
-        if (count($filters)) {
48
-            return $this->paginateBy(['and' => $filters], $perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true);
49
-        }
47
+		if (count($filters)) {
48
+			return $this->paginateBy(['and' => $filters], $perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true);
49
+		}
50 50
 
51
-        return $this->paginate($perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true);
52
-    }
51
+		return $this->paginate($perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true);
52
+	}
53 53
 
54
-    /**
55
-     * Fetch all records with relations from the storage.
56
-     *
57
-     * @param  array   $relations
58
-     * @param  string  $sortBy
59
-     * @param  boolean $desc
60
-     * @param  array   $columns
61
-     * @return collection
62
-     */
63
-    public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
64
-    {
65
-        return $this->repo->all($relations, $sortBy, $desc, $columns);
66
-    }
54
+	/**
55
+	 * Fetch all records with relations from the storage.
56
+	 *
57
+	 * @param  array   $relations
58
+	 * @param  string  $sortBy
59
+	 * @param  boolean $desc
60
+	 * @param  array   $columns
61
+	 * @return collection
62
+	 */
63
+	public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
64
+	{
65
+		return $this->repo->all($relations, $sortBy, $desc, $columns);
66
+	}
67 67
     
68
-    /**
69
-     * Fetch all records with relations from storage in pages.
70
-     *
71
-     * @param  integer $perPage
72
-     * @param  array   $relations
73
-     * @param  string  $sortBy
74
-     * @param  boolean $desc
75
-     * @param  array   $columns
76
-     * @return collection
77
-     */
78
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
79
-    {
80
-        return $this->repo->paginate($perPage, $relations, $sortBy, $desc, $columns);
81
-    }
68
+	/**
69
+	 * Fetch all records with relations from storage in pages.
70
+	 *
71
+	 * @param  integer $perPage
72
+	 * @param  array   $relations
73
+	 * @param  string  $sortBy
74
+	 * @param  boolean $desc
75
+	 * @param  array   $columns
76
+	 * @return collection
77
+	 */
78
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
79
+	{
80
+		return $this->repo->paginate($perPage, $relations, $sortBy, $desc, $columns);
81
+	}
82 82
 
83
-    /**
84
-     * Fetch all records with relations based on
85
-     * the given condition from storage in pages.
86
-     *
87
-     * @param  array   $conditions array of conditions
88
-     * @param  integer $perPage
89
-     * @param  array   $relations
90
-     * @param  string  $sortBy
91
-     * @param  boolean $desc
92
-     * @param  array   $columns
93
-     * @return collection
94
-     */
95
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
96
-    {
97
-        return $this->repo->paginateBy($conditions, $perPage, $relations, $sortBy, $desc, $columns);
98
-    }
83
+	/**
84
+	 * Fetch all records with relations based on
85
+	 * the given condition from storage in pages.
86
+	 *
87
+	 * @param  array   $conditions array of conditions
88
+	 * @param  integer $perPage
89
+	 * @param  array   $relations
90
+	 * @param  string  $sortBy
91
+	 * @param  boolean $desc
92
+	 * @param  array   $columns
93
+	 * @return collection
94
+	 */
95
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
96
+	{
97
+		return $this->repo->paginateBy($conditions, $perPage, $relations, $sortBy, $desc, $columns);
98
+	}
99 99
     
100
-    /**
101
-     * Save the given model to the storage.
102
-     *
103
-     * @param  array $data
104
-     * @return mixed
105
-     */
106
-    public function save(array $data)
107
-    {
108
-        return $this->repo->save($data);
109
-    }
100
+	/**
101
+	 * Save the given model to the storage.
102
+	 *
103
+	 * @param  array $data
104
+	 * @return mixed
105
+	 */
106
+	public function save(array $data)
107
+	{
108
+		return $this->repo->save($data);
109
+	}
110 110
 
111
-    /**
112
-     * Delete record from the storage based on the given
113
-     * condition.
114
-     *
115
-     * @param  var $value condition value
116
-     * @param  string $attribute condition column name
117
-     * @return void
118
-     */
119
-    public function delete($value, $attribute = 'id')
120
-    {
121
-        return $this->repo->delete($value, $attribute);
122
-    }
111
+	/**
112
+	 * Delete record from the storage based on the given
113
+	 * condition.
114
+	 *
115
+	 * @param  var $value condition value
116
+	 * @param  string $attribute condition column name
117
+	 * @return void
118
+	 */
119
+	public function delete($value, $attribute = 'id')
120
+	{
121
+		return $this->repo->delete($value, $attribute);
122
+	}
123 123
     
124
-    /**
125
-     * Fetch records from the storage based on the given
126
-     * id.
127
-     *
128
-     * @param  integer $id
129
-     * @param  array   $relations
130
-     * @param  array   $columns
131
-     * @return object
132
-     */
133
-    public function find($id, $relations = [], $columns = ['*'])
134
-    {
135
-        return $this->repo->find($id, $relations, $columns);
136
-    }
124
+	/**
125
+	 * Fetch records from the storage based on the given
126
+	 * id.
127
+	 *
128
+	 * @param  integer $id
129
+	 * @param  array   $relations
130
+	 * @param  array   $columns
131
+	 * @return object
132
+	 */
133
+	public function find($id, $relations = [], $columns = ['*'])
134
+	{
135
+		return $this->repo->find($id, $relations, $columns);
136
+	}
137 137
     
138
-    /**
139
-     * Fetch records from the storage based on the given
140
-     * condition.
141
-     *
142
-     * @param  array   $conditions array of conditions
143
-     * @param  array   $relations
144
-     * @param  string  $sortBy
145
-     * @param  boolean $desc
146
-     * @param  array   $columns
147
-     * @return collection
148
-     */
149
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
150
-    {
151
-        return $this->repo->findBy($conditions, $relations, $sortBy, $desc, $columns);
152
-    }
138
+	/**
139
+	 * Fetch records from the storage based on the given
140
+	 * condition.
141
+	 *
142
+	 * @param  array   $conditions array of conditions
143
+	 * @param  array   $relations
144
+	 * @param  string  $sortBy
145
+	 * @param  boolean $desc
146
+	 * @param  array   $columns
147
+	 * @return collection
148
+	 */
149
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
150
+	{
151
+		return $this->repo->findBy($conditions, $relations, $sortBy, $desc, $columns);
152
+	}
153 153
 
154
-    /**
155
-     * Fetch the first record from the storage based on the given
156
-     * condition.
157
-     *
158
-     * @param  array   $conditions array of conditions
159
-     * @param  array   $relations
160
-     * @param  array   $columns
161
-     * @return object
162
-     */
163
-    public function first($conditions, $relations = [], $columns = ['*'])
164
-    {
165
-        return $this->repo->first($conditions, $relations, $columns);
166
-    }
154
+	/**
155
+	 * Fetch the first record from the storage based on the given
156
+	 * condition.
157
+	 *
158
+	 * @param  array   $conditions array of conditions
159
+	 * @param  array   $relations
160
+	 * @param  array   $columns
161
+	 * @return object
162
+	 */
163
+	public function first($conditions, $relations = [], $columns = ['*'])
164
+	{
165
+		return $this->repo->first($conditions, $relations, $columns);
166
+	}
167 167
 
168
-    /**
169
-     * Return the deleted models in pages based on the given conditions.
170
-     *
171
-     * @param  array   $conditions array of conditions
172
-     * @param  integer $perPage
173
-     * @param  string  $sortBy
174
-     * @param  boolean $desc
175
-     * @param  array   $columns
176
-     * @return collection
177
-     */
178
-    public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*'])
179
-    {
180
-        return $this->repo->deleted($conditions, $perPage, $sortBy, $desc, $columns);
181
-    }
168
+	/**
169
+	 * Return the deleted models in pages based on the given conditions.
170
+	 *
171
+	 * @param  array   $conditions array of conditions
172
+	 * @param  integer $perPage
173
+	 * @param  string  $sortBy
174
+	 * @param  boolean $desc
175
+	 * @param  array   $columns
176
+	 * @return collection
177
+	 */
178
+	public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*'])
179
+	{
180
+		return $this->repo->deleted($conditions, $perPage, $sortBy, $desc, $columns);
181
+	}
182 182
 
183
-    /**
184
-     * Restore the deleted model.
185
-     *
186
-     * @param  integer $id
187
-     * @return void
188
-     */
189
-    public function restore($id)
190
-    {
191
-        return $this->repo->restore($id);
192
-    }
183
+	/**
184
+	 * Restore the deleted model.
185
+	 *
186
+	 * @param  integer $id
187
+	 * @return void
188
+	 */
189
+	public function restore($id)
190
+	{
191
+		return $this->repo->restore($id);
192
+	}
193 193
 
194
-    /**
195
-     * Prepare filters for repo.
196
-     *
197
-     * @param  array   $conditions
198
-     * @return array
199
-     */
200
-    public function constructFilters($conditions)
201
-    {
202
-        $filters = [];
203
-        $translatable = $this->repo->model->translatable ?? [];
204
-        foreach ($conditions as $key => $value) {
205
-            if ((in_array($key, $this->repo->model->fillable ?? []) || method_exists($this->repo->model, $key) || in_array($key, ['or', 'and'])) && $key !== 'trashed') {
206
-                /**
207
-                 * Prepare key based on the the requested lang if it was translatable.
208
-                 */
209
-                $key = in_array($key, $translatable) ? $key . '->' . (Session::get('locale') == 'all' ? 'en' : Session::get('locale')) : $key;
194
+	/**
195
+	 * Prepare filters for repo.
196
+	 *
197
+	 * @param  array   $conditions
198
+	 * @return array
199
+	 */
200
+	public function constructFilters($conditions)
201
+	{
202
+		$filters = [];
203
+		$translatable = $this->repo->model->translatable ?? [];
204
+		foreach ($conditions as $key => $value) {
205
+			if ((in_array($key, $this->repo->model->fillable ?? []) || method_exists($this->repo->model, $key) || in_array($key, ['or', 'and'])) && $key !== 'trashed') {
206
+				/**
207
+				 * Prepare key based on the the requested lang if it was translatable.
208
+				 */
209
+				$key = in_array($key, $translatable) ? $key . '->' . (Session::get('locale') == 'all' ? 'en' : Session::get('locale')) : $key;
210 210
 
211
-                /**
212
-                 * Convert 0/1 or true/false to boolean in case of not foreign key.
213
-                 */
214
-                if (filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null && strpos($key, '_id') === false && ! is_null($value)) {
215
-                    $filters[$key] = filter_var($value, FILTER_VALIDATE_BOOLEAN);
211
+				/**
212
+				 * Convert 0/1 or true/false to boolean in case of not foreign key.
213
+				 */
214
+				if (filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null && strpos($key, '_id') === false && ! is_null($value)) {
215
+					$filters[$key] = filter_var($value, FILTER_VALIDATE_BOOLEAN);
216 216
 
217
-                /**
218
-                 * Use in operator in case of foreign and comma seperated values.
219
-                 */
220
-                } elseif (! is_array($value) && strpos($key, '_id') && $value) {
221
-                    $filters[$key] = [
222
-                        'op' => 'in',
223
-                        'val' => explode(',', $value)
224
-                    ];
217
+				/**
218
+				 * Use in operator in case of foreign and comma seperated values.
219
+				 */
220
+				} elseif (! is_array($value) && strpos($key, '_id') && $value) {
221
+					$filters[$key] = [
222
+						'op' => 'in',
223
+						'val' => explode(',', $value)
224
+					];
225 225
 
226
-                /**
227
-                 * Use null operator in case of 0 value and foreign.
228
-                 */
229
-                } elseif (strpos($key, '_id') && $value == 0) {
230
-                    $filters[$key] = [
231
-                        'op' => 'null'
232
-                    ];
226
+				/**
227
+				 * Use null operator in case of 0 value and foreign.
228
+				 */
229
+				} elseif (strpos($key, '_id') && $value == 0) {
230
+					$filters[$key] = [
231
+						'op' => 'null'
232
+					];
233 233
 
234
-                /**
235
-                 * Consider values as a sub conditions if it is array.
236
-                 */
237
-                } elseif (is_array($value)) {
238
-                    $filters[$key] = $value;
234
+				/**
235
+				 * Consider values as a sub conditions if it is array.
236
+				 */
237
+				} elseif (is_array($value)) {
238
+					$filters[$key] = $value;
239 239
 
240
-                /**
241
-                 * Default string filteration.
242
-                 */
243
-                } elseif ($value) {
244
-                    $key = 'LOWER(' . $key . ')';
245
-                    $value = strtolower($value);
246
-                    $filters[$key] = [
247
-                        'op' => 'like',
248
-                        'val' => '%' . $value . '%'
249
-                    ];
250
-                }
251
-            }
252
-        }
240
+				/**
241
+				 * Default string filteration.
242
+				 */
243
+				} elseif ($value) {
244
+					$key = 'LOWER(' . $key . ')';
245
+					$value = strtolower($value);
246
+					$filters[$key] = [
247
+						'op' => 'like',
248
+						'val' => '%' . $value . '%'
249
+					];
250
+				}
251
+			}
252
+		}
253 253
 
254
-        return $filters;
255
-    }
254
+		return $filters;
255
+	}
256 256
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     {
39 39
         $translatable = $this->repo->model->translatable ?? [];
40 40
         $filters = $this->constructFilters($conditions);
41
-        $sortBy = in_array($sortBy, $translatable) ? $sortBy . '->' . Session::get('locale') : $sortBy;
41
+        $sortBy = in_array($sortBy, $translatable) ? $sortBy.'->'.Session::get('locale') : $sortBy;
42 42
 
43 43
         if ($trashed) {
44 44
             return $this->deleted(['and' => $filters], $perPage ?? 15, $sortBy ?? 'created_at', $desc ?? true);
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
                 /**
207 207
                  * Prepare key based on the the requested lang if it was translatable.
208 208
                  */
209
-                $key = in_array($key, $translatable) ? $key . '->' . (Session::get('locale') == 'all' ? 'en' : Session::get('locale')) : $key;
209
+                $key = in_array($key, $translatable) ? $key.'->'.(Session::get('locale') == 'all' ? 'en' : Session::get('locale')) : $key;
210 210
 
211 211
                 /**
212 212
                  * Convert 0/1 or true/false to boolean in case of not foreign key.
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
                 /**
218 218
                  * Use in operator in case of foreign and comma seperated values.
219 219
                  */
220
-                } elseif (! is_array($value) && strpos($key, '_id') && $value) {
220
+                } elseif ( ! is_array($value) && strpos($key, '_id') && $value) {
221 221
                     $filters[$key] = [
222 222
                         'op' => 'in',
223 223
                         'val' => explode(',', $value)
@@ -241,11 +241,11 @@  discard block
 block discarded – undo
241 241
                  * Default string filteration.
242 242
                  */
243 243
                 } elseif ($value) {
244
-                    $key = 'LOWER(' . $key . ')';
244
+                    $key = 'LOWER('.$key.')';
245 245
                     $value = strtolower($value);
246 246
                     $filters[$key] = [
247 247
                         'op' => 'like',
248
-                        'val' => '%' . $value . '%'
248
+                        'val' => '%'.$value.'%'
249 249
                     ];
250 250
                 }
251 251
             }
Please login to merge, or discard this patch.
src/Modules/Core/Interfaces/BaseRepositoryInterface.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -2,93 +2,93 @@
 block discarded – undo
2 2
 
3 3
 interface BaseRepositoryInterface
4 4
 {
5
-    /**
6
-     * Fetch all records with relations from the storage.
7
-     *
8
-     * @param  array  $relations
9
-     * @param  array  $sortBy
10
-     * @param  array  $desc
11
-     * @param  array  $columns
12
-     * @return collection
13
-     */
14
-    public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
5
+	/**
6
+	 * Fetch all records with relations from the storage.
7
+	 *
8
+	 * @param  array  $relations
9
+	 * @param  array  $sortBy
10
+	 * @param  array  $desc
11
+	 * @param  array  $columns
12
+	 * @return collection
13
+	 */
14
+	public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
15 15
 
16
-    /**
17
-     * Fetch all records with relations from storage in pages.
18
-     *
19
-     * @param  integer $perPage
20
-     * @param  array   $relations
21
-     * @param  array   $sortBy
22
-     * @param  array   $desc
23
-     * @param  array   $columns
24
-     * @return collection
25
-     */
26
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
16
+	/**
17
+	 * Fetch all records with relations from storage in pages.
18
+	 *
19
+	 * @param  integer $perPage
20
+	 * @param  array   $relations
21
+	 * @param  array   $sortBy
22
+	 * @param  array   $desc
23
+	 * @param  array   $columns
24
+	 * @return collection
25
+	 */
26
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
27 27
     
28
-    /**
29
-     * Fetch all records with relations based on
30
-     * the given condition from storage in pages.
31
-     *
32
-     * @param  array   $conditions array of conditions
33
-     * @param  integer $perPage
34
-     * @param  array   $relations
35
-     * @param  array   $sortBy
36
-     * @param  array   $desc
37
-     * @param  array   $columns
38
-     * @return collection
39
-     */
40
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
28
+	/**
29
+	 * Fetch all records with relations based on
30
+	 * the given condition from storage in pages.
31
+	 *
32
+	 * @param  array   $conditions array of conditions
33
+	 * @param  integer $perPage
34
+	 * @param  array   $relations
35
+	 * @param  array   $sortBy
36
+	 * @param  array   $desc
37
+	 * @param  array   $columns
38
+	 * @return collection
39
+	 */
40
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
41 41
 
42
-     /**
43
-      * Save the given model/models to the storage.
44
-      *
45
-      * @param  array   $data
46
-      * @return mixed
47
-      */
48
-    public function save(array $data);
42
+	 /**
43
+	  * Save the given model/models to the storage.
44
+	  *
45
+	  * @param  array   $data
46
+	  * @return mixed
47
+	  */
48
+	public function save(array $data);
49 49
 
50
-    /**
51
-     * Delete record from the storage based on the given
52
-     * condition.
53
-     *
54
-     * @param  var     $value condition value
55
-     * @param  string  $attribute condition column name
56
-     * @return integer affected rows
57
-     */
58
-    public function delete($value, $attribute = 'id');
50
+	/**
51
+	 * Delete record from the storage based on the given
52
+	 * condition.
53
+	 *
54
+	 * @param  var     $value condition value
55
+	 * @param  string  $attribute condition column name
56
+	 * @return integer affected rows
57
+	 */
58
+	public function delete($value, $attribute = 'id');
59 59
     
60
-    /**
61
-     * Fetch records from the storage based on the given
62
-     * id.
63
-     *
64
-     * @param  integer $id
65
-     * @param  array   $relations
66
-     * @param  array   $columns
67
-     * @return object
68
-     */
69
-    public function find($id, $relations = [], $columns = ['*']);
60
+	/**
61
+	 * Fetch records from the storage based on the given
62
+	 * id.
63
+	 *
64
+	 * @param  integer $id
65
+	 * @param  array   $relations
66
+	 * @param  array   $columns
67
+	 * @return object
68
+	 */
69
+	public function find($id, $relations = [], $columns = ['*']);
70 70
     
71
-    /**
72
-     * Fetch records from the storage based on the given
73
-     * condition.
74
-     *
75
-     * @param  array   $conditions array of conditions
76
-     * @param  array   $relations
77
-     * @param  array   $sortBy
78
-     * @param  array   $desc
79
-     * @param  array   $columns
80
-     * @return collection
81
-     */
82
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
71
+	/**
72
+	 * Fetch records from the storage based on the given
73
+	 * condition.
74
+	 *
75
+	 * @param  array   $conditions array of conditions
76
+	 * @param  array   $relations
77
+	 * @param  array   $sortBy
78
+	 * @param  array   $desc
79
+	 * @param  array   $columns
80
+	 * @return collection
81
+	 */
82
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
83 83
 
84
-    /**
85
-     * Fetch the first record fro the storage based on the given
86
-     * condition.
87
-     *
88
-     * @param  array   $conditions array of conditions
89
-     * @param  array   $relations
90
-     * @param  array   $columns
91
-     * @return object
92
-     */
93
-    public function first($conditions, $relations = [], $columns = ['*']);
84
+	/**
85
+	 * Fetch the first record fro the storage based on the given
86
+	 * condition.
87
+	 *
88
+	 * @param  array   $conditions array of conditions
89
+	 * @param  array   $relations
90
+	 * @param  array   $columns
91
+	 * @return object
92
+	 */
93
+	public function first($conditions, $relations = [], $columns = ['*']);
94 94
 }
Please login to merge, or discard this patch.
src/Modules/Core/Interfaces/BaseServiceInterface.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -2,93 +2,93 @@
 block discarded – undo
2 2
 
3 3
 interface BaseServiceInterface
4 4
 {
5
-    /**
6
-     * Fetch all records with relations from the storage.
7
-     *
8
-     * @param  array  $relations
9
-     * @param  array  $sortBy
10
-     * @param  array  $desc
11
-     * @param  array  $columns
12
-     * @return collection
13
-     */
14
-    public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
5
+	/**
6
+	 * Fetch all records with relations from the storage.
7
+	 *
8
+	 * @param  array  $relations
9
+	 * @param  array  $sortBy
10
+	 * @param  array  $desc
11
+	 * @param  array  $columns
12
+	 * @return collection
13
+	 */
14
+	public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
15 15
 
16
-    /**
17
-     * Fetch all records with relations from storage in pages.
18
-     *
19
-     * @param  integer $perPage
20
-     * @param  array   $relations
21
-     * @param  array   $sortBy
22
-     * @param  array   $desc
23
-     * @param  array   $columns
24
-     * @return collection
25
-     */
26
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
16
+	/**
17
+	 * Fetch all records with relations from storage in pages.
18
+	 *
19
+	 * @param  integer $perPage
20
+	 * @param  array   $relations
21
+	 * @param  array   $sortBy
22
+	 * @param  array   $desc
23
+	 * @param  array   $columns
24
+	 * @return collection
25
+	 */
26
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
27 27
     
28
-    /**
29
-     * Fetch all records with relations based on
30
-     * the given condition from storage in pages.
31
-     *
32
-     * @param  array   $conditions array of conditions
33
-     * @param  integer $perPage
34
-     * @param  array   $relations
35
-     * @param  array   $sortBy
36
-     * @param  array   $desc
37
-     * @param  array   $columns
38
-     * @return collection
39
-     */
40
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
28
+	/**
29
+	 * Fetch all records with relations based on
30
+	 * the given condition from storage in pages.
31
+	 *
32
+	 * @param  array   $conditions array of conditions
33
+	 * @param  integer $perPage
34
+	 * @param  array   $relations
35
+	 * @param  array   $sortBy
36
+	 * @param  array   $desc
37
+	 * @param  array   $columns
38
+	 * @return collection
39
+	 */
40
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
41 41
 
42
-     /**
43
-      * Save the given model/models to the storage.
44
-      *
45
-      * @param  array   $data
46
-      * @return mixed
47
-      */
48
-    public function save(array $data);
42
+	 /**
43
+	  * Save the given model/models to the storage.
44
+	  *
45
+	  * @param  array   $data
46
+	  * @return mixed
47
+	  */
48
+	public function save(array $data);
49 49
 
50
-    /**
51
-     * Delete record from the storage based on the given
52
-     * condition.
53
-     *
54
-     * @param  var     $value condition value
55
-     * @param  string  $attribute condition column name
56
-     * @return integer affected rows
57
-     */
58
-    public function delete($value, $attribute = 'id');
50
+	/**
51
+	 * Delete record from the storage based on the given
52
+	 * condition.
53
+	 *
54
+	 * @param  var     $value condition value
55
+	 * @param  string  $attribute condition column name
56
+	 * @return integer affected rows
57
+	 */
58
+	public function delete($value, $attribute = 'id');
59 59
     
60
-    /**
61
-     * Fetch records from the storage based on the given
62
-     * id.
63
-     *
64
-     * @param  integer $id
65
-     * @param  array   $relations
66
-     * @param  array   $columns
67
-     * @return object
68
-     */
69
-    public function find($id, $relations = [], $columns = ['*']);
60
+	/**
61
+	 * Fetch records from the storage based on the given
62
+	 * id.
63
+	 *
64
+	 * @param  integer $id
65
+	 * @param  array   $relations
66
+	 * @param  array   $columns
67
+	 * @return object
68
+	 */
69
+	public function find($id, $relations = [], $columns = ['*']);
70 70
     
71
-    /**
72
-     * Fetch records from the storage based on the given
73
-     * condition.
74
-     *
75
-     * @param  array   $conditions array of conditions
76
-     * @param  array   $relations
77
-     * @param  array   $sortBy
78
-     * @param  array   $desc
79
-     * @param  array   $columns
80
-     * @return collection
81
-     */
82
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
71
+	/**
72
+	 * Fetch records from the storage based on the given
73
+	 * condition.
74
+	 *
75
+	 * @param  array   $conditions array of conditions
76
+	 * @param  array   $relations
77
+	 * @param  array   $sortBy
78
+	 * @param  array   $desc
79
+	 * @param  array   $columns
80
+	 * @return collection
81
+	 */
82
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
83 83
 
84
-    /**
85
-     * Fetch the first record fro the storage based on the given
86
-     * condition.
87
-     *
88
-     * @param  array   $conditions array of conditions
89
-     * @param  array   $relations
90
-     * @param  array   $columns
91
-     * @return object
92
-     */
93
-    public function first($conditions, $relations = [], $columns = ['*']);
84
+	/**
85
+	 * Fetch the first record fro the storage based on the given
86
+	 * condition.
87
+	 *
88
+	 * @param  array   $conditions array of conditions
89
+	 * @param  array   $relations
90
+	 * @param  array   $columns
91
+	 * @return object
92
+	 */
93
+	public function first($conditions, $relations = [], $columns = ['*']);
94 94
 }
Please login to merge, or discard this patch.
src/Modules/Users/Repositories/UserRepository.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,6 @@
 block discarded – undo
3 3
 namespace App\Modules\Users\Repositories;
4 4
 
5 5
 use App\Modules\Core\BaseClasses\BaseRepository;
6
-use Illuminate\Support\Arr;
7 6
 use App\Modules\Users\AclUser;
8 7
 
9 8
 class UserRepository extends BaseRepository
Please login to merge, or discard this patch.
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -8,52 +8,52 @@
 block discarded – undo
8 8
 
9 9
 class UserRepository extends BaseRepository
10 10
 {
11
-    /**
12
-     * Init new object.
13
-     *
14
-     * @param   AclUser $model
15
-     * @return  void
16
-     */
17
-    public function __construct(AclUser $model)
18
-    {
19
-        parent::__construct($model);
20
-    }
11
+	/**
12
+	 * Init new object.
13
+	 *
14
+	 * @param   AclUser $model
15
+	 * @return  void
16
+	 */
17
+	public function __construct(AclUser $model)
18
+	{
19
+		parent::__construct($model);
20
+	}
21 21
 
22
-    /**
23
-     * Detach all roles from the given user.
24
-     *
25
-     * @param  mixed $user
26
-     * @return object
27
-     */
28
-    public function detachRoles($user)
29
-    {
30
-        $user = ! filter_var($user, FILTER_VALIDATE_INT) ? $user : $this->find($user);
31
-        $user->roles()->detach();
32
-    }
22
+	/**
23
+	 * Detach all roles from the given user.
24
+	 *
25
+	 * @param  mixed $user
26
+	 * @return object
27
+	 */
28
+	public function detachRoles($user)
29
+	{
30
+		$user = ! filter_var($user, FILTER_VALIDATE_INT) ? $user : $this->find($user);
31
+		$user->roles()->detach();
32
+	}
33 33
 
34
-    /**
35
-     * Attach role ids to the given user.
36
-     *
37
-     * @param  mixed $user
38
-     * @param  array $roleIds
39
-     * @return object
40
-     */
41
-    public function attachRoles($user, $roleIds)
42
-    {
43
-        $user = ! filter_var($user, FILTER_VALIDATE_INT) ? $user : $this->find($user);
44
-        $user->roles()->attach($roleIds);
45
-    }
34
+	/**
35
+	 * Attach role ids to the given user.
36
+	 *
37
+	 * @param  mixed $user
38
+	 * @param  array $roleIds
39
+	 * @return object
40
+	 */
41
+	public function attachRoles($user, $roleIds)
42
+	{
43
+		$user = ! filter_var($user, FILTER_VALIDATE_INT) ? $user : $this->find($user);
44
+		$user->roles()->attach($roleIds);
45
+	}
46 46
 
47
-    /**
48
-     * Count the given user the given roles.
49
-     *
50
-     * @param  mixed    $user
51
-     * @param  string[] $roles
52
-     * @return boolean
53
-     */
54
-    public function countRoles($user, $roles)
55
-    {
56
-        $user = ! filter_var($user, FILTER_VALIDATE_INT) ? $user : $this->find($user);
57
-        return $user->roles()->whereIn('name', $roles)->count();
58
-    }
47
+	/**
48
+	 * Count the given user the given roles.
49
+	 *
50
+	 * @param  mixed    $user
51
+	 * @param  string[] $roles
52
+	 * @return boolean
53
+	 */
54
+	public function countRoles($user, $roles)
55
+	{
56
+		$user = ! filter_var($user, FILTER_VALIDATE_INT) ? $user : $this->find($user);
57
+		return $user->roles()->whereIn('name', $roles)->count();
58
+	}
59 59
 }
Please login to merge, or discard this patch.
src/Modules/Permissions/Resources/Lang/en/errors.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@
 block discarded – undo
2 2
 
3 3
 return [
4 4
     
5
-    /**
6
-     * Here goes your error messages.
7
-     */
5
+	/**
6
+	 * Here goes your error messages.
7
+	 */
8 8
 
9 9
 ];
Please login to merge, or discard this patch.
src/Modules/Core/Facades/Errors.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 
5 5
 class Errors extends Facade
6 6
 {
7
-    protected static function getFacadeAccessor()
8
-    {
9
-        return 'Errors';
10
-    }
7
+	protected static function getFacadeAccessor()
8
+	{
9
+		return 'Errors';
10
+	}
11 11
 }
Please login to merge, or discard this patch.
src/Modules/Core/Errors/Errors.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,8 +19,8 @@
 block discarded – undo
19 19
     public function __call($name, $arguments)
20 20
     {
21 21
         foreach (\Module::all() as $module) {
22
-            $nameSpace = 'App\\Modules\\' . $module['basename'];
23
-            $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors';
22
+            $nameSpace = 'App\\Modules\\'.$module['basename'];
23
+            $class = $nameSpace.'\\Errors\\'.$module['basename'].'Errors';
24 24
 
25 25
             if (class_exists($class)) {
26 26
                 $class = \App::make($class);
Please login to merge, or discard this patch.
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -6,28 +6,28 @@
 block discarded – undo
6 6
 
7 7
 class Errors implements BaseFactoryInterface
8 8
 {
9
-    /**
10
-     * Construct the config class name based on
11
-     * the method name called, search in the
12
-     * given namespaces for the class and
13
-     * return an instance.
14
-     *
15
-     * @param  string $name the called method name
16
-     * @param  array  $arguments the method arguments
17
-     * @return object
18
-     */
19
-    public function __call($name, $arguments)
20
-    {
21
-        foreach (\Module::all() as $module) {
22
-            $nameSpace = 'App\\Modules\\' . $module['basename'];
23
-            $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors';
9
+	/**
10
+	 * Construct the config class name based on
11
+	 * the method name called, search in the
12
+	 * given namespaces for the class and
13
+	 * return an instance.
14
+	 *
15
+	 * @param  string $name the called method name
16
+	 * @param  array  $arguments the method arguments
17
+	 * @return object
18
+	 */
19
+	public function __call($name, $arguments)
20
+	{
21
+		foreach (\Module::all() as $module) {
22
+			$nameSpace = 'App\\Modules\\' . $module['basename'];
23
+			$class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors';
24 24
 
25
-            if (class_exists($class)) {
26
-                $class = \App::make($class);
27
-                if (method_exists($class, $name)) {
28
-                    return call_user_func_array([$class, $name], $arguments);
29
-                }
30
-            }
31
-        }
32
-    }
25
+			if (class_exists($class)) {
26
+				$class = \App::make($class);
27
+				if (method_exists($class, $name)) {
28
+					return call_user_func_array([$class, $name], $arguments);
29
+				}
30
+			}
31
+		}
32
+	}
33 33
 }
Please login to merge, or discard this patch.
src/Modules/Users/Resources/Lang/en/errors.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -2,21 +2,21 @@
 block discarded – undo
2 2
 
3 3
 return [
4 4
     
5
-    /**
6
-     * Here goes your error messages.
7
-     */
8
-    'unAuthorized'            => 'Please login before any action',
9
-    'invalidRefreshToken'     => 'Invalid refresh token',
10
-    'noPermissions'           => 'No permissions',
11
-    'loginFailed'             => 'Wrong mail or password',
12
-    'noSocialEmail'           => 'Couldn\'t retrieve email',
13
-    'userAlreadyRegistered'   => 'User already registered. Please login using email and password',
14
-    'userIsBlocked'           => 'You have been blocked',
15
-    'invalidResetToken'       => 'Reset password token is invalid',
16
-    'invalidResetPassword'    => 'Reset password is invalid',
17
-    'invalidOldPassword'      => 'Old password is invalid',
18
-    'invalidConfirmationCode' => 'Confirmation link expired or already used',
19
-    'emailNotConfirmed'       => 'Your email isn\'t confirmed',
20
-    'emailAlreadyConfirmed'   => 'Your email is already confirmed'
5
+	/**
6
+	 * Here goes your error messages.
7
+	 */
8
+	'unAuthorized'            => 'Please login before any action',
9
+	'invalidRefreshToken'     => 'Invalid refresh token',
10
+	'noPermissions'           => 'No permissions',
11
+	'loginFailed'             => 'Wrong mail or password',
12
+	'noSocialEmail'           => 'Couldn\'t retrieve email',
13
+	'userAlreadyRegistered'   => 'User already registered. Please login using email and password',
14
+	'userIsBlocked'           => 'You have been blocked',
15
+	'invalidResetToken'       => 'Reset password token is invalid',
16
+	'invalidResetPassword'    => 'Reset password is invalid',
17
+	'invalidOldPassword'      => 'Old password is invalid',
18
+	'invalidConfirmationCode' => 'Confirmation link expired or already used',
19
+	'emailNotConfirmed'       => 'Your email isn\'t confirmed',
20
+	'emailAlreadyConfirmed'   => 'Your email is already confirmed'
21 21
 
22 22
 ];
Please login to merge, or discard this patch.