@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $model = new Model(); |
121 | 121 | $relations = []; |
122 | 122 | |
123 | - DB::transaction(function () use (&$model, &$relations, $data) { |
|
123 | + DB::transaction(function() use (&$model, &$relations, $data) { |
|
124 | 124 | |
125 | 125 | $model = $this->prepareModel($data); |
126 | 126 | $model->save(); |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | */ |
158 | 158 | public function delete(string $value, string $attribute = 'id'): bool |
159 | 159 | { |
160 | - DB::transaction(function () use ($value, $attribute) { |
|
161 | - $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) { |
|
160 | + DB::transaction(function() use ($value, $attribute) { |
|
161 | + $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function($model) { |
|
162 | 162 | $model->delete(); |
163 | 163 | }); |
164 | 164 | }); |
@@ -247,8 +247,8 @@ discard block |
||
247 | 247 | { |
248 | 248 | $model = $this->model->onlyTrashed()->find($id); |
249 | 249 | |
250 | - if (!$model) { |
|
251 | - Errors::notFound(class_basename($this->model) . ' with id : ' . $id); |
|
250 | + if ( ! $model) { |
|
251 | + Errors::notFound(class_basename($this->model).' with id : '.$id); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | $model->restore(); |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | $modelClass = $this->model; |
268 | 268 | $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
269 | 269 | |
270 | - if (!$model) { |
|
271 | - Errors::notFound(class_basename($modelClass) . ' with id : ' . $data['id']); |
|
270 | + if ( ! $model) { |
|
271 | + Errors::notFound(class_basename($modelClass).' with id : '.$data['id']); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | foreach ($data as $key => $value) { |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | Core::$relation() && |
298 | 298 | in_array(class_basename($model->$key()), ['MorphToMany', 'BelongsToMany']) |
299 | 299 | ) { |
300 | - if (!$relatedModels || !count($relatedModels)) { |
|
300 | + if ( ! $relatedModels || ! count($relatedModels)) { |
|
301 | 301 | /** |
302 | 302 | * Mark the relation to be deleted. |
303 | 303 | */ |
@@ -324,14 +324,14 @@ discard block |
||
324 | 324 | */ |
325 | 325 | protected function prepareRelatedModel(mixed $relatedModelData, Model $relationBaseModel): Model |
326 | 326 | { |
327 | - if (!is_array($relatedModelData)) { // if the relation is integer id |
|
327 | + if ( ! is_array($relatedModelData)) { // if the relation is integer id |
|
328 | 328 | $relatedModel = $relationBaseModel->lockForUpdate()->find($relatedModelData); |
329 | 329 | } else { |
330 | 330 | $relatedModel = Arr::has($relatedModelData, 'id') ? $relationBaseModel->lockForUpdate()->find($relatedModelData['id']) : new $relationBaseModel; |
331 | 331 | } |
332 | 332 | |
333 | - if (!$relatedModel) { |
|
334 | - Errors::notFound(class_basename($relationBaseModel) . ' with id : ' . $relatedModelData['id']); |
|
333 | + if ( ! $relatedModel) { |
|
334 | + Errors::notFound(class_basename($relationBaseModel).' with id : '.$relatedModelData['id']); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | if (is_array($relatedModelData)) { |
@@ -401,11 +401,11 @@ discard block |
||
401 | 401 | |
402 | 402 | if ($key == 'and') { |
403 | 403 | $conditions = $this->constructConditions($value, $model); |
404 | - $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']) . ' {op} '; |
|
404 | + $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} '; |
|
405 | 405 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
406 | 406 | } elseif ($key == 'or') { |
407 | 407 | $conditions = $this->constructConditions($value, $model); |
408 | - $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']) . ' {op} '; |
|
408 | + $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} '; |
|
409 | 409 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
410 | 410 | } else { |
411 | 411 | if (is_array($value)) { |
@@ -421,38 +421,38 @@ discard block |
||
421 | 421 | } |
422 | 422 | |
423 | 423 | if (strtolower($operator) == 'between') { |
424 | - $conditionString .= $key . ' >= ? and '; |
|
424 | + $conditionString .= $key.' >= ? and '; |
|
425 | 425 | $conditionValues[] = $value1; |
426 | 426 | |
427 | - $conditionString .= $key . ' <= ? {op} '; |
|
427 | + $conditionString .= $key.' <= ? {op} '; |
|
428 | 428 | $conditionValues[] = $value2; |
429 | 429 | } elseif (strtolower($operator) == 'in') { |
430 | 430 | $conditionValues = array_merge($conditionValues, $value); |
431 | 431 | $inBindingsString = rtrim(str_repeat('?,', count($value)), ','); |
432 | - $conditionString .= $key . ' in (' . rtrim($inBindingsString, ',') . ') {op} '; |
|
432 | + $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} '; |
|
433 | 433 | } elseif (strtolower($operator) == 'null') { |
434 | - $conditionString .= $key . ' is null {op} '; |
|
434 | + $conditionString .= $key.' is null {op} '; |
|
435 | 435 | } elseif (strtolower($operator) == 'not null') { |
436 | - $conditionString .= $key . ' is not null {op} '; |
|
436 | + $conditionString .= $key.' is not null {op} '; |
|
437 | 437 | } elseif (strtolower($operator) == 'has') { |
438 | 438 | $sql = $model->withTrashed()->withoutGlobalScopes()->has($key)->toSql(); |
439 | 439 | $bindings = $model->withTrashed()->withoutGlobalScopes()->has($key)->getBindings(); |
440 | 440 | if ($value) { |
441 | 441 | $conditions = $this->constructConditions($value, $model->$key()->getRelated()); |
442 | - $conditionString .= substr(substr($sql, strpos($sql, 'exists')), 0, -1) . ' and ' . $conditions['conditionString'] . ') {op} '; |
|
442 | + $conditionString .= substr(substr($sql, strpos($sql, 'exists')), 0, -1).' and '.$conditions['conditionString'].') {op} '; |
|
443 | 443 | $conditionValues = array_merge($conditionValues, $bindings); |
444 | 444 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
445 | 445 | } else { |
446 | - $conditionString .= substr(substr($sql, strpos($sql, 'exists')), 0, -1) . ') {op} '; |
|
446 | + $conditionString .= substr(substr($sql, strpos($sql, 'exists')), 0, -1).') {op} '; |
|
447 | 447 | $conditionValues = array_merge($conditionValues, $bindings); |
448 | 448 | } |
449 | 449 | } else { |
450 | - $conditionString .= $key . ' ' . $operator . ' ? {op} '; |
|
450 | + $conditionString .= $key.' '.$operator.' ? {op} '; |
|
451 | 451 | $conditionValues[] = $value; |
452 | 452 | } |
453 | 453 | } |
454 | 454 | } |
455 | - $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
455 | + $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
456 | 456 | return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
457 | 457 | } |
458 | 458 | |
@@ -468,10 +468,10 @@ discard block |
||
468 | 468 | $value = $removeLast === false ? $value : substr($value, 0, $removeLast); |
469 | 469 | $path = explode('->', $value); |
470 | 470 | $field = array_shift($path); |
471 | - $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) { |
|
472 | - return '"' . $part . '"'; |
|
471 | + $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function($part) { |
|
472 | + return '"'.$part.'"'; |
|
473 | 473 | })->implode('.')); |
474 | 474 | |
475 | - return $removeLast === false ? $result : $result . ')'; |
|
475 | + return $removeLast === false ? $result : $result.')'; |
|
476 | 476 | } |
477 | 477 | } |