@@ -16,8 +16,6 @@ |
||
| 16 | 16 | use Anavel\Crud\Abstractor\Exceptions\AbstractorException; |
| 17 | 17 | use Illuminate\Http\Request; |
| 18 | 18 | use Illuminate\Support\Collection; |
| 19 | -use League\Flysystem\Adapter\Local; |
|
| 20 | -use League\Flysystem\Filesystem; |
|
| 21 | 19 | |
| 22 | 20 | class Model implements ModelAbstractorContract |
| 23 | 21 | { |
@@ -127,13 +127,13 @@ discard block |
||
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | $customDisplayedColumns = $this->getConfigValue($action, 'display'); |
| 130 | - $customHiddenColumns = $this->getConfigValue($action, 'hide') ? : []; |
|
| 130 | + $customHiddenColumns = $this->getConfigValue($action, 'hide') ?: []; |
|
| 131 | 131 | |
| 132 | 132 | $columns = array(); |
| 133 | - if (! empty($customDisplayedColumns) && is_array($customDisplayedColumns)) { |
|
| 133 | + if (!empty($customDisplayedColumns) && is_array($customDisplayedColumns)) { |
|
| 134 | 134 | foreach ($customDisplayedColumns as $customColumn) { |
| 135 | - if (! array_key_exists($customColumn, $tableColumns)) { |
|
| 136 | - throw new AbstractorException("Column " . $customColumn . " does not exist on " . $this->getModel()); |
|
| 135 | + if (!array_key_exists($customColumn, $tableColumns)) { |
|
| 136 | + throw new AbstractorException("Column ".$customColumn." does not exist on ".$this->getModel()); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | $columns[$customColumn] = $tableColumns[$customColumn]; |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | $relations = collect(); |
| 166 | 166 | |
| 167 | - if (! empty($configRelations)) { |
|
| 167 | + if (!empty($configRelations)) { |
|
| 168 | 168 | foreach ($configRelations as $relationName => $configRelation) { |
| 169 | 169 | if (is_int($relationName)) { |
| 170 | 170 | $relationName = $configRelation; |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | |
| 173 | 173 | $config = []; |
| 174 | 174 | if ($configRelation !== $relationName) { |
| 175 | - if (! is_array($configRelation)) { |
|
| 175 | + if (!is_array($configRelation)) { |
|
| 176 | 176 | $config['type'] = $configRelation; |
| 177 | 177 | } else { |
| 178 | 178 | $config = $configRelation; |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | $secondaryRelations = $relation->getSecondaryRelations(); |
| 188 | 188 | |
| 189 | 189 | |
| 190 | - if (! $secondaryRelations->isEmpty()) { |
|
| 190 | + if (!$secondaryRelations->isEmpty()) { |
|
| 191 | 191 | $relations->put($relationName, |
| 192 | 192 | collect(['relation' => $relation, 'secondaryRelations' => $secondaryRelations])); |
| 193 | 193 | } else { |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | { |
| 210 | 210 | $columns = $this->getColumns('list'); |
| 211 | 211 | |
| 212 | - $fieldsPresentation = $this->getConfigValue('fields_presentation') ? : []; |
|
| 212 | + $fieldsPresentation = $this->getConfigValue('fields_presentation') ?: []; |
|
| 213 | 213 | |
| 214 | 214 | $fields = array(); |
| 215 | 215 | foreach ($columns as $name => $column) { |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | { |
| 245 | 245 | $columns = $this->getColumns('detail'); |
| 246 | 246 | |
| 247 | - $fieldsPresentation = $this->getConfigValue('fields_presentation') ? : []; |
|
| 247 | + $fieldsPresentation = $this->getConfigValue('fields_presentation') ?: []; |
|
| 248 | 248 | |
| 249 | 249 | $fields = array(); |
| 250 | 250 | foreach ($columns as $name => $column) { |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | |
| 285 | 285 | $fields = array(); |
| 286 | 286 | foreach ($columns as $name => $column) { |
| 287 | - if (! in_array($name, $this->getReadOnlyColumns())) { |
|
| 287 | + if (!in_array($name, $this->getReadOnlyColumns())) { |
|
| 288 | 288 | $presentation = null; |
| 289 | 289 | if (array_key_exists($name, $this->fieldsPresentation)) { |
| 290 | 290 | $presentation = $this->fieldsPresentation[$name]; |
@@ -305,17 +305,17 @@ discard block |
||
| 305 | 305 | ->setConfig($config) |
| 306 | 306 | ->get(); |
| 307 | 307 | |
| 308 | - if (! empty($this->instance) && ! empty($this->instance->getAttribute($name))) { |
|
| 308 | + if (!empty($this->instance) && !empty($this->instance->getAttribute($name))) { |
|
| 309 | 309 | $field->setValue($this->instance->getAttribute($name)); |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | $fields[$arrayKey][] = $field; |
| 313 | 313 | |
| 314 | - if (! empty($config['form_type']) && $config['form_type'] === 'file') { |
|
| 314 | + if (!empty($config['form_type']) && $config['form_type'] === 'file') { |
|
| 315 | 315 | $field = $this->fieldFactory |
| 316 | 316 | ->setColumn($column) |
| 317 | 317 | ->setConfig([ |
| 318 | - 'name' => $name . '__delete', |
|
| 318 | + 'name' => $name.'__delete', |
|
| 319 | 319 | 'presentation' => null, |
| 320 | 320 | 'form_type' => 'checkbox', |
| 321 | 321 | 'validation' => null, |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | { |
| 360 | 360 | /** @var \ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager $modelManager */ |
| 361 | 361 | $modelManager = App::make('ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'); |
| 362 | - if (! empty($this->instance)) { |
|
| 362 | + if (!empty($this->instance)) { |
|
| 363 | 363 | $item = $this->instance; |
| 364 | 364 | } else { |
| 365 | 365 | $item = $modelManager->getModelInstance($this->getModel()); |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | return; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - if (! empty($fields['main'])) { |
|
| 374 | + if (!empty($fields['main'])) { |
|
| 375 | 375 | $skipNext = false; |
| 376 | 376 | foreach ($fields['main'] as $key => $field) { |
| 377 | 377 | if ($skipNext === true) { |
@@ -382,19 +382,19 @@ discard block |
||
| 382 | 382 | |
| 383 | 383 | if (get_class($field->getFormField()) === \FormManager\Fields\File::class) { |
| 384 | 384 | $handleResult = $this->handleField($request, $item, $fields, $key, 'main', $fieldName); |
| 385 | - if (! empty($handleResult['skipNext'])) { |
|
| 385 | + if (!empty($handleResult['skipNext'])) { |
|
| 386 | 386 | $skipNext = $handleResult['skipNext']; |
| 387 | 387 | } |
| 388 | - if (! empty($handleResult['requestValue'])) { |
|
| 388 | + if (!empty($handleResult['requestValue'])) { |
|
| 389 | 389 | $requestValue = $handleResult['requestValue']; |
| 390 | 390 | } |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - if (! $field->saveIfEmpty() && empty($requestValue)) { |
|
| 393 | + if (!$field->saveIfEmpty() && empty($requestValue)) { |
|
| 394 | 394 | continue; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - if (! empty($requestValue)) { |
|
| 397 | + if (!empty($requestValue)) { |
|
| 398 | 398 | $item->setAttribute( |
| 399 | 399 | $fieldName, |
| 400 | 400 | $field->applyFunctions($requestValue) |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | $this->setInstance($item); |
| 409 | 409 | |
| 410 | 410 | |
| 411 | - if (! empty($relations = $this->getRelations())) { |
|
| 411 | + if (!empty($relations = $this->getRelations())) { |
|
| 412 | 412 | foreach ($relations as $relationKey => $relation) { |
| 413 | 413 | if ($relation instanceof Collection) { |
| 414 | 414 | $input = $request->input($relationKey); |
@@ -9,6 +9,9 @@ |
||
| 9 | 9 | |
| 10 | 10 | trait HandleFiles |
| 11 | 11 | { |
| 12 | + /** |
|
| 13 | + * @param string $groupName |
|
| 14 | + */ |
|
| 12 | 15 | protected function handleField(Request $request, $item, array $fields, $currentKey, $groupName, $fieldName) |
| 13 | 16 | { |
| 14 | 17 | $modelFolder = $this->slug . DIRECTORY_SEPARATOR; |
@@ -9,19 +9,19 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | trait HandleFiles |
| 11 | 11 | { |
| 12 | - protected function handleField(Request $request, $item, array $fields, $currentKey, $groupName, $fieldName) |
|
| 12 | + protected function handleField(Request $request, $item, array $fields, $currentKey, $groupName, $fieldName) |
|
| 13 | 13 | { |
| 14 | - $modelFolder = $this->slug . DIRECTORY_SEPARATOR; |
|
| 14 | + $modelFolder = $this->slug.DIRECTORY_SEPARATOR; |
|
| 15 | 15 | $basePath = base_path(config('anavel-crud.uploads_path')); |
| 16 | - $modelPath = $basePath . $modelFolder; |
|
| 16 | + $modelPath = $basePath.$modelFolder; |
|
| 17 | 17 | $skipNext = false; |
| 18 | 18 | $requestValue = null; |
| 19 | - if (! empty($fields[$groupName][$currentKey + 1]) && $fields[$groupName][$currentKey + 1]->getName() === $fieldName . '__delete') { |
|
| 19 | + if (!empty($fields[$groupName][$currentKey + 1]) && $fields[$groupName][$currentKey + 1]->getName() === $fieldName.'__delete') { |
|
| 20 | 20 | //We never want to save this field, it doesn't exist in the DB |
| 21 | 21 | $skipNext = true; |
| 22 | 22 | |
| 23 | 23 | //If user wants to delete the existing file |
| 24 | - if (! empty($request->input("main.{$fieldName}__delete"))) { |
|
| 24 | + if (!empty($request->input("main.{$fieldName}__delete"))) { |
|
| 25 | 25 | $adapter = new Local($basePath); |
| 26 | 26 | $filesystem = new Filesystem($adapter); |
| 27 | 27 | if ($filesystem->has($item->$fieldName)) { |
@@ -38,18 +38,18 @@ discard block |
||
| 38 | 38 | ]; |
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | - if ($request->hasFile($groupName .'.'.$fieldName)) { |
|
| 42 | - $fileName = uniqid() . '.' . $request->file($groupName .'.'.$fieldName)->getClientOriginalExtension(); |
|
| 41 | + if ($request->hasFile($groupName.'.'.$fieldName)) { |
|
| 42 | + $fileName = uniqid().'.'.$request->file($groupName.'.'.$fieldName)->getClientOriginalExtension(); |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - $request->file($groupName .'.'.$fieldName)->move( |
|
| 45 | + $request->file($groupName.'.'.$fieldName)->move( |
|
| 46 | 46 | $modelPath, |
| 47 | 47 | $fileName |
| 48 | 48 | ); |
| 49 | 49 | |
| 50 | - $requestValue = $modelFolder . $fileName; |
|
| 51 | - } elseif (! $request->file($groupName .'.'.$fieldName)->isValid()) { |
|
| 52 | - throw new \Exception($request->file($groupName .'.'.$fieldName)->getErrorMessage()); |
|
| 50 | + $requestValue = $modelFolder.$fileName; |
|
| 51 | + } elseif (!$request->file($groupName.'.'.$fieldName)->isValid()) { |
|
| 52 | + throw new \Exception($request->file($groupName.'.'.$fieldName)->getErrorMessage()); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | return [ |