@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | public function __construct() |
| 18 | 18 | { |
| 19 | - $this->model = \App::make($this->getModel()); |
|
| 19 | + $this->model = \App::make($this->getModel()); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -55,14 +55,14 @@ discard block |
||
| 55 | 55 | /** |
| 56 | 56 | * Construct the select conditions for the model. |
| 57 | 57 | */ |
| 58 | - $model->where(function ($q) use ($query, $conditionColumns, $relations){ |
|
| 58 | + $model->where(function($q) use ($query, $conditionColumns, $relations){ |
|
| 59 | 59 | |
| 60 | 60 | if (count($conditionColumns)) |
| 61 | 61 | { |
| 62 | 62 | /** |
| 63 | 63 | * Use the first element in the model columns to construct the first condition. |
| 64 | 64 | */ |
| 65 | - $q->where(\DB::raw('LOWER(' . array_shift($conditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 65 | + $q->where(\DB::raw('LOWER('.array_shift($conditionColumns).')'), 'LIKE', '%'.strtolower($query).'%'); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | foreach ($conditionColumns as $column) |
| 72 | 72 | { |
| 73 | - $q->orWhere(\DB::raw('LOWER(' . $column . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 73 | + $q->orWhere(\DB::raw('LOWER('.$column.')'), 'LIKE', '%'.strtolower($query).'%'); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | /** |
| 92 | 92 | * Construct the relation condition. |
| 93 | 93 | */ |
| 94 | - $q->orWhereHas($relation, function ($subModel) use ($query, $relation){ |
|
| 94 | + $q->orWhereHas($relation, function($subModel) use ($query, $relation){ |
|
| 95 | 95 | |
| 96 | - $subModel->where(function ($q) use ($query, $relation){ |
|
| 96 | + $subModel->where(function($q) use ($query, $relation){ |
|
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | 99 | * Get columns of the relation. |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | /** |
| 106 | 106 | * Use the first element in the relation model columns to construct the first condition. |
| 107 | 107 | */ |
| 108 | - $q->where(\DB::raw('LOWER(' . array_shift($subConditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 108 | + $q->where(\DB::raw('LOWER('.array_shift($subConditionColumns).')'), 'LIKE', '%'.strtolower($query).'%'); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | foreach ($subConditionColumns as $subConditionColumn) |
| 115 | 115 | { |
| 116 | - $q->orWhere(\DB::raw('LOWER(' . $subConditionColumn . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 116 | + $q->orWhere(\DB::raw('LOWER('.$subConditionColumn.')'), 'LIKE', '%'.strtolower($query).'%'); |
|
| 117 | 117 | } |
| 118 | 118 | }); |
| 119 | 119 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | $modelClass = $this->model; |
| 175 | 175 | $relations = []; |
| 176 | 176 | |
| 177 | - \DB::transaction(function () use (&$model, &$relations, $data, $saveLog, $modelClass) { |
|
| 177 | + \DB::transaction(function() use (&$model, &$relations, $data, $saveLog, $modelClass) { |
|
| 178 | 178 | /** |
| 179 | 179 | * If the id is present in the data then select the model for updating, |
| 180 | 180 | * else create new model. |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
| 184 | 184 | if ( ! $model) |
| 185 | 185 | { |
| 186 | - \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']); |
|
| 186 | + \ErrorHandler::notFound(class_basename($modelClass).' with id : '.$data['id']); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | */ |
| 242 | 242 | if ( ! $relationModel) |
| 243 | 243 | { |
| 244 | - \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']); |
|
| 244 | + \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | /** |
| 253 | 253 | * Prevent the sub relations or attributes not in the fillable. |
| 254 | 254 | */ |
| 255 | - if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
| 255 | + if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
| 256 | 256 | { |
| 257 | 257 | $relationModel->$attr = $val; |
| 258 | 258 | } |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | */ |
| 283 | 283 | if ( ! $relationModel) |
| 284 | 284 | { |
| 285 | - \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']); |
|
| 285 | + \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | foreach ($value as $relationAttribute => $relationValue) |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | } |
| 428 | 428 | else |
| 429 | 429 | { |
| 430 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){ |
|
| 430 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) use ($data, $saveLog){ |
|
| 431 | 431 | $model->update($data); |
| 432 | 432 | $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
| 433 | 433 | }); |
@@ -446,11 +446,11 @@ discard block |
||
| 446 | 446 | { |
| 447 | 447 | if ($attribute == 'id') |
| 448 | 448 | { |
| 449 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
| 449 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
| 450 | 450 | $model = $this->model->lockForUpdate()->find($value); |
| 451 | 451 | if ( ! $model) |
| 452 | 452 | { |
| 453 | - \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value); |
|
| 453 | + \ErrorHandler::notFound(class_basename($this->model).' with id : '.$value); |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | $model->delete(); |
@@ -459,8 +459,8 @@ discard block |
||
| 459 | 459 | } |
| 460 | 460 | else |
| 461 | 461 | { |
| 462 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
| 463 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($saveLog){ |
|
| 462 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
| 463 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) use ($saveLog){ |
|
| 464 | 464 | $model->delete(); |
| 465 | 465 | $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
| 466 | 466 | }); |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | { |
| 498 | 498 | $conditions = $this->constructConditions($conditions, $this->model); |
| 499 | 499 | $sort = $desc ? 'desc' : 'asc'; |
| 500 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
| 500 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | /** |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | - return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);; |
|
| 540 | + return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); ; |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | /** |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | |
| 553 | 553 | if ( ! $model) |
| 554 | 554 | { |
| 555 | - \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $id); |
|
| 555 | + \ErrorHandler::notFound(class_basename($this->model).' with id : '.$id); |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | $model->restore(); |
@@ -572,13 +572,13 @@ discard block |
||
| 572 | 572 | if ($key == 'and') |
| 573 | 573 | { |
| 574 | 574 | $conditions = $this->constructConditions($value, $model); |
| 575 | - $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']) . ' {op} '; |
|
| 575 | + $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} '; |
|
| 576 | 576 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 577 | 577 | } |
| 578 | 578 | else if ($key == 'or') |
| 579 | 579 | { |
| 580 | 580 | $conditions = $this->constructConditions($value, $model); |
| 581 | - $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']) . ' {op} '; |
|
| 581 | + $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} '; |
|
| 582 | 582 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 583 | 583 | } |
| 584 | 584 | else |
@@ -603,41 +603,41 @@ discard block |
||
| 603 | 603 | |
| 604 | 604 | if (strtolower($operator) == 'between') |
| 605 | 605 | { |
| 606 | - $conditionString .= $key . ' >= ? and '; |
|
| 606 | + $conditionString .= $key.' >= ? and '; |
|
| 607 | 607 | $conditionValues[] = $value1; |
| 608 | 608 | |
| 609 | - $conditionString .= $key . ' <= ? {op} '; |
|
| 609 | + $conditionString .= $key.' <= ? {op} '; |
|
| 610 | 610 | $conditionValues[] = $value2; |
| 611 | 611 | } |
| 612 | 612 | elseif (strtolower($operator) == 'in') |
| 613 | 613 | { |
| 614 | 614 | $conditionValues = array_merge($conditionValues, $value); |
| 615 | 615 | $inBindingsString = rtrim(str_repeat('?,', count($value)), ','); |
| 616 | - $conditionString .= $key . ' in (' . rtrim($inBindingsString, ',') . ') {op} '; |
|
| 616 | + $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} '; |
|
| 617 | 617 | } |
| 618 | 618 | elseif (strtolower($operator) == 'null') |
| 619 | 619 | { |
| 620 | - $conditionString .= $key . ' is null {op} '; |
|
| 620 | + $conditionString .= $key.' is null {op} '; |
|
| 621 | 621 | } |
| 622 | 622 | elseif (strtolower($operator) == 'not null') |
| 623 | 623 | { |
| 624 | - $conditionString .= $key . ' is not null {op} '; |
|
| 624 | + $conditionString .= $key.' is not null {op} '; |
|
| 625 | 625 | } |
| 626 | 626 | elseif (strtolower($operator) == 'has') |
| 627 | 627 | { |
| 628 | 628 | $sql = $model->withTrashed()->has($key)->toSql(); |
| 629 | 629 | $conditions = $this->constructConditions($value, $model->$key()->getRelated()); |
| 630 | - $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')') . ' and ' . $conditions['conditionString'] . ') {op} '; |
|
| 630 | + $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} '; |
|
| 631 | 631 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 632 | 632 | } |
| 633 | 633 | else |
| 634 | 634 | { |
| 635 | - $conditionString .= $key . ' ' . $operator . ' ? {op} '; |
|
| 635 | + $conditionString .= $key.' '.$operator.' ? {op} '; |
|
| 636 | 636 | $conditionValues[] = $value; |
| 637 | 637 | } |
| 638 | 638 | } |
| 639 | 639 | } |
| 640 | - $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
| 640 | + $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
| 641 | 641 | return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
| 642 | 642 | } |
| 643 | 643 | |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
| 36 | 36 | $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
| 37 | 37 | $this->repo = call_user_func_array("\Core::{$this->model}", []); |
| 38 | - $route = explode('@',\Route::currentRouteAction())[1]; |
|
| 38 | + $route = explode('@', \Route::currentRouteAction())[1]; |
|
| 39 | 39 | |
| 40 | 40 | $this->checkPermission($route); |
| 41 | 41 | $this->setRelations($route); |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | $this->getPostData($route, $reflectionMethod, $validationRules); |
| 63 | 63 | |
| 64 | 64 | preg_match('/api\/v1\/([^#]+)\//iU', $route['uri'], $module); |
| 65 | - preg_match('/api\/v1\/' . $module[1] . '\/([^#]+)\//iU', $route['uri'], $model); |
|
| 65 | + preg_match('/api\/v1\/'.$module[1].'\/([^#]+)\//iU', $route['uri'], $model); |
|
| 66 | 66 | $docData['modules'][$module[1]][$model[1]][] = $route; |
| 67 | 67 | |
| 68 | 68 | $this->getModels($classProperties['model'], $docData); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | protected function getRoutes() |
| 82 | 82 | { |
| 83 | - return collect(\Route::getRoutes())->map(function ($route) { |
|
| 83 | + return collect(\Route::getRoutes())->map(function($route) { |
|
| 84 | 84 | if (strpos($route->uri(), 'api/v') !== false) |
| 85 | 85 | { |
| 86 | 86 | return [ |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | ]; |
| 113 | 113 | |
| 114 | 114 | |
| 115 | - if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) |
|
| 115 | + if ( ! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) |
|
| 116 | 116 | { |
| 117 | 117 | $route['headers']['Authrization'] = 'bearer {token}'; |
| 118 | 118 | } |
@@ -165,16 +165,16 @@ discard block |
||
| 165 | 165 | } |
| 166 | 166 | else |
| 167 | 167 | { |
| 168 | - $route['body'] = eval('return ' . $match[1] . ';'); |
|
| 168 | + $route['body'] = eval('return '.$match[1].';'); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | foreach ($route['body'] as &$rule) |
| 172 | 172 | { |
| 173 | - if(strpos($rule, 'unique')) |
|
| 173 | + if (strpos($rule, 'unique')) |
|
| 174 | 174 | { |
| 175 | 175 | $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
| 176 | 176 | } |
| 177 | - elseif(strpos($rule, 'exists')) |
|
| 177 | + elseif (strpos($rule, 'exists')) |
|
| 178 | 178 | { |
| 179 | 179 | $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
| 180 | 180 | } |
@@ -247,10 +247,10 @@ discard block |
||
| 247 | 247 | $model = factory($modelClass)->make(); |
| 248 | 248 | $modelArr = $model->toArray(); |
| 249 | 249 | |
| 250 | - if ( $model->trans && ! $model->trans->count()) |
|
| 250 | + if ($model->trans && ! $model->trans->count()) |
|
| 251 | 251 | { |
| 252 | 252 | $modelArr['trans'] = [ |
| 253 | - 'en' => factory($modelClass . 'Translation')->make()->toArray() |
|
| 253 | + 'en' => factory($modelClass.'Translation')->make()->toArray() |
|
| 254 | 254 | ]; |
| 255 | 255 | } |
| 256 | 256 | |