@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * to preform actions like (add, edit ... etc). |
13 | 13 | * @var string |
14 | 14 | */ |
15 | - protected $model = 'users'; |
|
15 | + protected $model = 'users'; |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * List of all route actions that the base api controller |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * to check before add. |
34 | 34 | * @var array |
35 | 35 | */ |
36 | - protected $validationRules = [ |
|
36 | + protected $validationRules = [ |
|
37 | 37 | 'email' => 'required|email|unique:users,email,{id}', |
38 | 38 | 'password' => 'min:6' |
39 | 39 | ]; |
@@ -12,11 +12,11 @@ |
||
12 | 12 | */ |
13 | 13 | public function up() |
14 | 14 | { |
15 | - Schema::create('logs', function (Blueprint $table) { |
|
15 | + Schema::create('logs', function(Blueprint $table) { |
|
16 | 16 | $table->increments('id'); |
17 | - $table->string('action',100); |
|
18 | - $table->string('item_name',100); |
|
19 | - $table->string('item_type',100); |
|
17 | + $table->string('action', 100); |
|
18 | + $table->string('item_name', 100); |
|
19 | + $table->string('item_type', 100); |
|
20 | 20 | $table->integer('item_id'); |
21 | 21 | $table->integer('user_id'); |
22 | 22 | $table->softDeletes(); |
@@ -29,6 +29,6 @@ |
||
29 | 29 | |
30 | 30 | public function notFound($text) |
31 | 31 | { |
32 | - return ['status' => 404, 'message' => 'The requested ' . $text . ' not found']; |
|
32 | + return ['status' => 404, 'message' => 'The requested '.$text.' not found']; |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -5,7 +5,7 @@ |
||
5 | 5 | public function getConfig() |
6 | 6 | { |
7 | 7 | $customSettings = []; |
8 | - Settings::get(['key', 'value'])->each(function ($setting) use (&$customSettings){ |
|
8 | + Settings::get(['key', 'value'])->each(function($setting) use (&$customSettings){ |
|
9 | 9 | $customSettings[$setting['key']] = $setting['value']; |
10 | 10 | }); |
11 | 11 |
@@ -18,7 +18,7 @@ |
||
18 | 18 | { |
19 | 19 | foreach ($this->getRepoNameSpace() as $repoNameSpace) |
20 | 20 | { |
21 | - $class = rtrim($repoNameSpace, '\\') . '\\' . ucfirst(str_singular($name)) . 'Repository'; |
|
21 | + $class = rtrim($repoNameSpace, '\\').'\\'.ucfirst(str_singular($name)).'Repository'; |
|
22 | 22 | if (class_exists($class)) |
23 | 23 | { |
24 | 24 | return \App::make($class); |
@@ -12,5 +12,5 @@ |
||
12 | 12 | * to preform actions like (add, edit ... etc). |
13 | 13 | * @var string |
14 | 14 | */ |
15 | - protected $model = 'logs'; |
|
15 | + protected $model = 'logs'; |
|
16 | 16 | } |
@@ -3,7 +3,7 @@ |
||
3 | 3 | use Illuminate\Database\Eloquent\Model; |
4 | 4 | use Illuminate\Database\Eloquent\SoftDeletes; |
5 | 5 | |
6 | -class Log extends Model{ |
|
6 | +class Log extends Model { |
|
7 | 7 | |
8 | 8 | use SoftDeletes; |
9 | 9 | protected $table = 'logs'; |
@@ -60,26 +60,26 @@ discard block |
||
60 | 60 | $conditionColumns = $this->model->getFillable(); |
61 | 61 | $sort = $desc ? 'desc' : 'asc'; |
62 | 62 | |
63 | - $model->where(function ($q) use ($query, $conditionColumns, $relations){ |
|
64 | - $q->where(\DB::raw('LOWER(CAST(' . array_shift($conditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
63 | + $model->where(function($q) use ($query, $conditionColumns, $relations){ |
|
64 | + $q->where(\DB::raw('LOWER(CAST('.array_shift($conditionColumns).' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
65 | 65 | foreach ($conditionColumns as $column) |
66 | 66 | { |
67 | - $q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
67 | + $q->orWhere(\DB::raw('LOWER(CAST('.$column.' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
68 | 68 | } |
69 | 69 | foreach ($relations as $relation) |
70 | 70 | { |
71 | 71 | $relation = explode('.', $relation)[0]; |
72 | 72 | if (\Core::$relation()) |
73 | 73 | { |
74 | - $q->orWhereHas($relation, function ($subModel) use ($query, $relation){ |
|
74 | + $q->orWhereHas($relation, function($subModel) use ($query, $relation){ |
|
75 | 75 | |
76 | - $subModel->where(function ($q) use ($query, $relation){ |
|
76 | + $subModel->where(function($q) use ($query, $relation){ |
|
77 | 77 | |
78 | 78 | $subConditionColumns = \Core::$relation()->model->getFillable(); |
79 | - $q->where(\DB::raw('LOWER(CAST(' . array_shift($subConditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
79 | + $q->where(\DB::raw('LOWER(CAST('.array_shift($subConditionColumns).' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
80 | 80 | foreach ($subConditionColumns as $subConditionColumn) |
81 | 81 | { |
82 | - $q->orWhere(\DB::raw('LOWER(CAST(' . $subConditionColumn . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
82 | + $q->orWhere(\DB::raw('LOWER(CAST('.$subConditionColumn.' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
83 | 83 | } |
84 | 84 | }); |
85 | 85 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | $relations = []; |
142 | 142 | $with = []; |
143 | 143 | |
144 | - \DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) { |
|
144 | + \DB::transaction(function() use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) { |
|
145 | 145 | /** |
146 | 146 | * If the id is present in the data then select the model for updating, |
147 | 147 | * else create new model. |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
151 | 151 | if ( ! $model) |
152 | 152 | { |
153 | - $error = \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']); |
|
153 | + $error = \ErrorHandler::notFound(class_basename($modelClass).' with id : '.$data['id']); |
|
154 | 154 | abort($error['status'], $error['message']); |
155 | 155 | } |
156 | 156 | |
@@ -182,13 +182,13 @@ discard block |
||
182 | 182 | $relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel; |
183 | 183 | if ( ! $relationModel) |
184 | 184 | { |
185 | - $error = \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']); |
|
185 | + $error = \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
|
186 | 186 | abort($error['status'], $error['message']); |
187 | 187 | } |
188 | 188 | |
189 | 189 | foreach ($val as $attr => $val) |
190 | 190 | { |
191 | - if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
191 | + if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
192 | 192 | { |
193 | 193 | $relationModel->$attr = $val; |
194 | 194 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel; |
203 | 203 | if ( ! $relationModel) |
204 | 204 | { |
205 | - $error = \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']); |
|
205 | + $error = \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
|
206 | 206 | abort($error['status'], $error['message']); |
207 | 207 | } |
208 | 208 | |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | public function saveMany(array $data) |
291 | 291 | { |
292 | 292 | $result = []; |
293 | - \DB::transaction(function () use (&$result, $data) { |
|
293 | + \DB::transaction(function() use (&$result, $data) { |
|
294 | 294 | foreach ($data as $key => $value) |
295 | 295 | { |
296 | 296 | $result[] = $this->save($value); |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | $model ? $model->update($data) : 0; |
317 | 317 | $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $value, $model) : false; |
318 | 318 | } |
319 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){ |
|
319 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) use ($data, $saveLog){ |
|
320 | 320 | $model->update($data); |
321 | 321 | $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
322 | 322 | }); |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | { |
335 | 335 | if ($attribute == 'id') |
336 | 336 | { |
337 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
337 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
338 | 338 | $model = $this->model->lockForUpdate()->find($value); |
339 | 339 | $model->delete(); |
340 | 340 | $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false; |
@@ -342,8 +342,8 @@ discard block |
||
342 | 342 | } |
343 | 343 | else |
344 | 344 | { |
345 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
346 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){ |
|
345 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
346 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) { |
|
347 | 347 | $model->delete(); |
348 | 348 | $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
349 | 349 | }); |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | { |
381 | 381 | $conditions = $this->constructConditions($conditions); |
382 | 382 | $sort = $desc ? 'desc' : 'asc'; |
383 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
383 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
@@ -411,21 +411,21 @@ discard block |
||
411 | 411 | { |
412 | 412 | if ($key == 'and') |
413 | 413 | { |
414 | - $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
414 | + $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']).' {op} '; |
|
415 | 415 | $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
416 | 416 | } |
417 | 417 | else if ($key == 'or') |
418 | 418 | { |
419 | - $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
419 | + $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']).' {op} '; |
|
420 | 420 | $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
421 | 421 | } |
422 | 422 | else |
423 | 423 | { |
424 | - $conditionString .= $key . '=? {op} '; |
|
424 | + $conditionString .= $key.'=? {op} '; |
|
425 | 425 | $conditionValues[] = $value; |
426 | 426 | } |
427 | 427 | } |
428 | - $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
428 | + $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
429 | 429 | return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
430 | 430 | } |
431 | 431 |