@@ -3,14 +3,14 @@ |
||
3 | 3 | use Illuminate\Database\Eloquent\Model; |
4 | 4 | use Illuminate\Database\Eloquent\SoftDeletes; |
5 | 5 | |
6 | -class Settings extends Model{ |
|
6 | +class Settings extends Model { |
|
7 | 7 | |
8 | 8 | use SoftDeletes; |
9 | 9 | protected $table = 'settings'; |
10 | 10 | protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
11 | 11 | protected $hidden = ['deleted_at']; |
12 | 12 | protected $guarded = ['id', 'key']; |
13 | - protected $fillable = ['name','value']; |
|
13 | + protected $fillable = ['name', 'value']; |
|
14 | 14 | |
15 | 15 | public function getCreatedAtAttribute($value) |
16 | 16 | { |
@@ -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); |
@@ -79,26 +79,26 @@ discard block |
||
79 | 79 | $conditionColumns = $this->model->getFillable(); |
80 | 80 | $sort = $desc ? 'desc' : 'asc'; |
81 | 81 | |
82 | - $model->where(function ($q) use ($query, $conditionColumns, $relations){ |
|
83 | - $q->where(\DB::raw('LOWER(CAST(' . array_shift($conditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
82 | + $model->where(function($q) use ($query, $conditionColumns, $relations){ |
|
83 | + $q->where(\DB::raw('LOWER(CAST('.array_shift($conditionColumns).' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
84 | 84 | foreach ($conditionColumns as $column) |
85 | 85 | { |
86 | - $q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
86 | + $q->orWhere(\DB::raw('LOWER(CAST('.$column.' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
87 | 87 | } |
88 | 88 | foreach ($relations as $relation) |
89 | 89 | { |
90 | 90 | $relation = explode('.', $relation)[0]; |
91 | 91 | if (\Core::$relation()) |
92 | 92 | { |
93 | - $q->orWhereHas($relation, function ($subModel) use ($query, $relation){ |
|
93 | + $q->orWhereHas($relation, function($subModel) use ($query, $relation){ |
|
94 | 94 | |
95 | - $subModel->where(function ($q) use ($query, $relation){ |
|
95 | + $subModel->where(function($q) use ($query, $relation){ |
|
96 | 96 | |
97 | 97 | $subConditionColumns = \Core::$relation()->model->getFillable(); |
98 | - $q->where(\DB::raw('LOWER(CAST(' . array_shift($subConditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
98 | + $q->where(\DB::raw('LOWER(CAST('.array_shift($subConditionColumns).' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
99 | 99 | foreach ($subConditionColumns as $column) |
100 | 100 | { |
101 | - $q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
101 | + $q->orWhere(\DB::raw('LOWER(CAST('.$column.' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
102 | 102 | } |
103 | 103 | }); |
104 | 104 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $relations = []; |
161 | 161 | $with = []; |
162 | 162 | |
163 | - \DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) { |
|
163 | + \DB::transaction(function() use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) { |
|
164 | 164 | /** |
165 | 165 | * If the id is present in the data then select the model for updating, |
166 | 166 | * else create new model. |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
170 | 170 | if ( ! $model) |
171 | 171 | { |
172 | - $error = $this->errorHandler->notFound(class_basename($modelClass) . ' with id : ' . $data['id']); |
|
172 | + $error = $this->errorHandler->notFound(class_basename($modelClass).' with id : '.$data['id']); |
|
173 | 173 | abort($error['status'], $error['message']); |
174 | 174 | } |
175 | 175 | |
@@ -201,13 +201,13 @@ discard block |
||
201 | 201 | $relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel; |
202 | 202 | if ( ! $relationModel) |
203 | 203 | { |
204 | - $error = $this->errorHandler->notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']); |
|
204 | + $error = $this->errorHandler->notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
|
205 | 205 | abort($error['status'], $error['message']); |
206 | 206 | } |
207 | 207 | |
208 | 208 | foreach ($val as $attr => $val) |
209 | 209 | { |
210 | - if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
210 | + if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
211 | 211 | { |
212 | 212 | $relationModel->$attr = $val; |
213 | 213 | } |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | $relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel; |
222 | 222 | if ( ! $relationModel) |
223 | 223 | { |
224 | - $error = $this->errorHandler->notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']); |
|
224 | + $error = $this->errorHandler->notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
|
225 | 225 | abort($error['status'], $error['message']); |
226 | 226 | } |
227 | 227 | |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | public function saveMany(array $data) |
310 | 310 | { |
311 | 311 | $result = []; |
312 | - \DB::transaction(function () use (&$result, $data) { |
|
312 | + \DB::transaction(function() use (&$result, $data) { |
|
313 | 313 | foreach ($data as $key => $value) |
314 | 314 | { |
315 | 315 | $result[] = $this->save($value); |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | $model ? $model->update($data) : 0; |
336 | 336 | $saveLog ? $this->logs->saveLog('update', class_basename($this->model), $this->getModel(), $value, $model) : false; |
337 | 337 | } |
338 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){ |
|
338 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) use ($data, $saveLog){ |
|
339 | 339 | $model->update($data); |
340 | 340 | $saveLog ? $this->logs->saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
341 | 341 | }); |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | { |
354 | 354 | if ($attribute == 'id') |
355 | 355 | { |
356 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
356 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
357 | 357 | $model = $this->model->lockForUpdate()->find($value); |
358 | 358 | $model->delete(); |
359 | 359 | $saveLog ? $this->logs->saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false; |
@@ -361,8 +361,8 @@ discard block |
||
361 | 361 | } |
362 | 362 | else |
363 | 363 | { |
364 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
365 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){ |
|
364 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
365 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) { |
|
366 | 366 | $model->delete(); |
367 | 367 | $saveLog ? $this->logs->saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
368 | 368 | }); |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | { |
400 | 400 | $conditions = $this->constructConditions($conditions); |
401 | 401 | $sort = $desc ? 'desc' : 'asc'; |
402 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
402 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -430,21 +430,21 @@ discard block |
||
430 | 430 | { |
431 | 431 | if ($key == 'and') |
432 | 432 | { |
433 | - $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
433 | + $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']).' {op} '; |
|
434 | 434 | $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
435 | 435 | } |
436 | 436 | else if ($key == 'or') |
437 | 437 | { |
438 | - $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
438 | + $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']).' {op} '; |
|
439 | 439 | $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
440 | 440 | } |
441 | 441 | else |
442 | 442 | { |
443 | - $conditionString .= $key . '=? {op} '; |
|
443 | + $conditionString .= $key.'=? {op} '; |
|
444 | 444 | $conditionValues[] = $value; |
445 | 445 | } |
446 | 446 | } |
447 | - $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
447 | + $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
448 | 448 | return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
449 | 449 | } |
450 | 450 |
@@ -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 |
@@ -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 |
@@ -47,7 +47,7 @@ |
||
47 | 47 | $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
48 | 48 | |
49 | 49 | $this->relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
50 | - $route = explode('@',\Route::currentRouteAction())[1]; |
|
50 | + $route = explode('@', \Route::currentRouteAction())[1]; |
|
51 | 51 | $this->checkPermission(explode('_', snake_case($route))[1]); |
52 | 52 | } |
53 | 53 |
@@ -13,14 +13,14 @@ |
||
13 | 13 | * to preform actions like (add, edit ... etc). |
14 | 14 | * @var string |
15 | 15 | */ |
16 | - protected $model = 'settings'; |
|
16 | + protected $model = 'settings'; |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * The validations rules used by the base api controller |
20 | 20 | * to check before add. |
21 | 21 | * @var array |
22 | 22 | */ |
23 | - protected $validationRules = [ |
|
23 | + protected $validationRules = [ |
|
24 | 24 | 'name' => 'required|string|max:100', |
25 | 25 | 'value' => 'required|string|max:100' |
26 | 26 | ]; |
@@ -12,11 +12,11 @@ |
||
12 | 12 | */ |
13 | 13 | public function up() |
14 | 14 | { |
15 | - Schema::create('settings', function (Blueprint $table) { |
|
15 | + Schema::create('settings', function(Blueprint $table) { |
|
16 | 16 | $table->increments('id'); |
17 | - $table->string('name',100); |
|
18 | - $table->string('key',100)->unique(); |
|
19 | - $table->string('value',100); |
|
17 | + $table->string('name', 100); |
|
18 | + $table->string('key', 100)->unique(); |
|
19 | + $table->string('value', 100); |
|
20 | 20 | $table->softDeletes(); |
21 | 21 | $table->timestamps(); |
22 | 22 | }); |
@@ -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'; |