@@ -47,14 +47,14 @@ discard block |
||
47 | 47 | |
48 | 48 | $this->app->bind( |
49 | 49 | 'Anavel\Crud\Contracts\Abstractor\FieldFactory', |
50 | - function () { |
|
50 | + function() { |
|
51 | 51 | return new FieldAbstractorFactory(new FormFactory); |
52 | 52 | } |
53 | 53 | ); |
54 | 54 | |
55 | 55 | $this->app->bind( |
56 | 56 | 'Anavel\Crud\Contracts\Abstractor\RelationFactory', |
57 | - function () { |
|
57 | + function() { |
|
58 | 58 | return new RelationAbstractorFactory( |
59 | 59 | $this->app['ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'], |
60 | 60 | $this->app['Anavel\Crud\Contracts\Abstractor\FieldFactory'] |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | |
65 | 65 | $this->app->bind( |
66 | 66 | 'Anavel\Crud\Contracts\Abstractor\ModelFactory', |
67 | - function () { |
|
67 | + function() { |
|
68 | 68 | return new ModelAbstractorFactory( |
69 | 69 | config('anavel-crud.models'), |
70 | 70 | $this->app['ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'], |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | $this->app->bind( |
79 | 79 | 'Anavel\Crud\Contracts\Form\Generator', |
80 | - function () { |
|
80 | + function() { |
|
81 | 81 | return new FormGenerator(new FormFactory); |
82 | 82 | } |
83 | 83 | ); |
@@ -5,7 +5,7 @@ |
||
5 | 5 | 'prefix' => 'crud', |
6 | 6 | 'namespace' => 'Anavel\Crud\Http\Controllers' |
7 | 7 | ], |
8 | - function () { |
|
8 | + function() { |
|
9 | 9 | Route::get('/', [ |
10 | 10 | 'as' => 'anavel-crud.home', |
11 | 11 | 'uses' => 'HomeController@index' |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | use EasySlugger\Slugger; |
4 | 4 | |
5 | -if (! function_exists('slugify')) { |
|
5 | +if (!function_exists('slugify')) { |
|
6 | 6 | /** |
7 | 7 | * Generate slug |
8 | 8 | * |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | } |
16 | 16 | } |
17 | 17 | |
18 | -if (! function_exists('uniqueSlugify')) { |
|
18 | +if (!function_exists('uniqueSlugify')) { |
|
19 | 19 | /** |
20 | 20 | * Generate unique slug |
21 | 21 | * |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | } |
29 | 29 | } |
30 | 30 | |
31 | -if (! function_exists('transcrud')) { |
|
31 | +if (!function_exists('transcrud')) { |
|
32 | 32 | /** |
33 | 33 | * Translate string but remove file key if translation not found |
34 | 34 | * |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | function transcrud($text) |
39 | 39 | { |
40 | - $translation = trans('anavel-crud::models.' . $text); |
|
40 | + $translation = trans('anavel-crud::models.'.$text); |
|
41 | 41 | |
42 | 42 | return str_replace('anavel-crud::models.', '', $translation); |
43 | 43 | } |
@@ -85,6 +85,9 @@ discard block |
||
85 | 85 | return transcrud($this->name); |
86 | 86 | } |
87 | 87 | |
88 | + /** |
|
89 | + * @return string |
|
90 | + */ |
|
88 | 91 | public function getModel() |
89 | 92 | { |
90 | 93 | return $this->model; |
@@ -334,7 +337,7 @@ discard block |
||
334 | 337 | } |
335 | 338 | |
336 | 339 | /** |
337 | - * @param array $requestForm |
|
340 | + * @param array $request |
|
338 | 341 | * @return mixed |
339 | 342 | */ |
340 | 343 | public function persist(Request $request) |
@@ -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 | { |
@@ -128,13 +128,13 @@ discard block |
||
128 | 128 | } |
129 | 129 | |
130 | 130 | $customDisplayedColumns = $this->getConfigValue($action, 'display'); |
131 | - $customHiddenColumns = $this->getConfigValue($action, 'hide') ? : []; |
|
131 | + $customHiddenColumns = $this->getConfigValue($action, 'hide') ?: []; |
|
132 | 132 | |
133 | 133 | $columns = array(); |
134 | - if (! empty($customDisplayedColumns) && is_array($customDisplayedColumns)) { |
|
134 | + if (!empty($customDisplayedColumns) && is_array($customDisplayedColumns)) { |
|
135 | 135 | foreach ($customDisplayedColumns as $customColumn) { |
136 | - if (! array_key_exists($customColumn, $tableColumns)) { |
|
137 | - throw new AbstractorException("Column " . $customColumn . " does not exist on " . $this->getModel()); |
|
136 | + if (!array_key_exists($customColumn, $tableColumns)) { |
|
137 | + throw new AbstractorException("Column ".$customColumn." does not exist on ".$this->getModel()); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $columns[$customColumn] = $tableColumns[$customColumn]; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | |
166 | 166 | $relations = collect(); |
167 | 167 | |
168 | - if (! empty($configRelations)) { |
|
168 | + if (!empty($configRelations)) { |
|
169 | 169 | foreach ($configRelations as $relationName => $configRelation) { |
170 | 170 | if (is_int($relationName)) { |
171 | 171 | $relationName = $configRelation; |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | |
174 | 174 | $config = []; |
175 | 175 | if ($configRelation !== $relationName) { |
176 | - if (! is_array($configRelation)) { |
|
176 | + if (!is_array($configRelation)) { |
|
177 | 177 | $config['type'] = $configRelation; |
178 | 178 | } else { |
179 | 179 | $config = $configRelation; |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $secondaryRelations = $relation->getSecondaryRelations(); |
189 | 189 | |
190 | 190 | |
191 | - if (! $secondaryRelations->isEmpty()) { |
|
191 | + if (!$secondaryRelations->isEmpty()) { |
|
192 | 192 | $relations->put( |
193 | 193 | $relationName, |
194 | 194 | collect(['relation' => $relation, 'secondaryRelations' => $secondaryRelations]) |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | { |
213 | 213 | $columns = $this->getColumns('list'); |
214 | 214 | |
215 | - $fieldsPresentation = $this->getConfigValue('fields_presentation') ? : []; |
|
215 | + $fieldsPresentation = $this->getConfigValue('fields_presentation') ?: []; |
|
216 | 216 | |
217 | 217 | $fields = array(); |
218 | 218 | foreach ($columns as $name => $column) { |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | { |
248 | 248 | $columns = $this->getColumns('detail'); |
249 | 249 | |
250 | - $fieldsPresentation = $this->getConfigValue('fields_presentation') ? : []; |
|
250 | + $fieldsPresentation = $this->getConfigValue('fields_presentation') ?: []; |
|
251 | 251 | |
252 | 252 | $fields = array(); |
253 | 253 | foreach ($columns as $name => $column) { |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | |
288 | 288 | $fields = array(); |
289 | 289 | foreach ($columns as $name => $column) { |
290 | - if (! in_array($name, $this->getReadOnlyColumns())) { |
|
290 | + if (!in_array($name, $this->getReadOnlyColumns())) { |
|
291 | 291 | $presentation = null; |
292 | 292 | if (array_key_exists($name, $this->fieldsPresentation)) { |
293 | 293 | $presentation = $this->fieldsPresentation[$name]; |
@@ -308,24 +308,24 @@ discard block |
||
308 | 308 | ->setConfig($config) |
309 | 309 | ->get(); |
310 | 310 | |
311 | - if (! empty($this->instance) && ! empty($this->instance->getAttribute($name))) { |
|
311 | + if (!empty($this->instance) && !empty($this->instance->getAttribute($name))) { |
|
312 | 312 | $field->setValue($this->instance->getAttribute($name)); |
313 | 313 | } |
314 | 314 | |
315 | 315 | $fields[$arrayKey][$name] = $field; |
316 | 316 | |
317 | - if (! empty($config['form_type']) && $config['form_type'] === 'file') { |
|
317 | + if (!empty($config['form_type']) && $config['form_type'] === 'file') { |
|
318 | 318 | $field = $this->fieldFactory |
319 | 319 | ->setColumn($column) |
320 | 320 | ->setConfig([ |
321 | - 'name' => $name . '__delete', |
|
321 | + 'name' => $name.'__delete', |
|
322 | 322 | 'presentation' => null, |
323 | 323 | 'form_type' => 'checkbox', |
324 | 324 | 'no_validate' => true, |
325 | 325 | 'functions' => null |
326 | 326 | ]) |
327 | 327 | ->get(); |
328 | - $fields[$arrayKey][$name . '__delete'] = $field; |
|
328 | + $fields[$arrayKey][$name.'__delete'] = $field; |
|
329 | 329 | } |
330 | 330 | } |
331 | 331 | } |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | { |
363 | 363 | /** @var \ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager $modelManager */ |
364 | 364 | $modelManager = App::make('ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'); |
365 | - if (! empty($this->instance)) { |
|
365 | + if (!empty($this->instance)) { |
|
366 | 366 | $item = $this->instance; |
367 | 367 | } else { |
368 | 368 | $item = $modelManager->getModelInstance($this->getModel()); |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | return; |
375 | 375 | } |
376 | 376 | |
377 | - if (! empty($fields['main'])) { |
|
377 | + if (!empty($fields['main'])) { |
|
378 | 378 | $skip = null; |
379 | 379 | foreach ($fields['main'] as $key => $field) { |
380 | 380 | /** @var FieldContract $field */ |
@@ -399,20 +399,20 @@ discard block |
||
399 | 399 | |
400 | 400 | if (get_class($field->getFormField()) === \FormManager\Fields\File::class) { |
401 | 401 | $handleResult = $this->handleField($request, $item, $fields['main'], 'main', $fieldName); |
402 | - if (! empty($handleResult['skip'])) { |
|
402 | + if (!empty($handleResult['skip'])) { |
|
403 | 403 | $skip = $handleResult['skip']; |
404 | 404 | } |
405 | - if (! empty($handleResult['requestValue'])) { |
|
405 | + if (!empty($handleResult['requestValue'])) { |
|
406 | 406 | $requestValue = $handleResult['requestValue']; |
407 | 407 | } |
408 | 408 | } |
409 | 409 | |
410 | 410 | |
411 | - if (! $field->saveIfEmpty() && empty($requestValue)) { |
|
411 | + if (!$field->saveIfEmpty() && empty($requestValue)) { |
|
412 | 412 | continue; |
413 | 413 | } |
414 | 414 | |
415 | - if (! empty($requestValue) || (empty($requestValue) && ! empty($item->getAttribute($fieldName)))) { |
|
415 | + if (!empty($requestValue) || (empty($requestValue) && !empty($item->getAttribute($fieldName)))) { |
|
416 | 416 | $item->setAttribute( |
417 | 417 | $fieldName, |
418 | 418 | $field->applyFunctions($requestValue) |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | $this->setInstance($item); |
427 | 427 | |
428 | 428 | |
429 | - if (! empty($relations = $this->getRelations())) { |
|
429 | + if (!empty($relations = $this->getRelations())) { |
|
430 | 430 | foreach ($relations as $relationKey => $relation) { |
431 | 431 | if ($relation instanceof Collection) { |
432 | 432 | $input = $request->input($relationKey); |
@@ -27,7 +27,7 @@ |
||
27 | 27 | /** |
28 | 28 | * @param array $config |
29 | 29 | * @param string $columnName |
30 | - * @return array |
|
30 | + * @return \Doctrine\DBAL\Schema\Column |
|
31 | 31 | */ |
32 | 32 | public function setConfig(array $config, $columnName) |
33 | 33 | { |
@@ -17,11 +17,11 @@ |
||
17 | 17 | */ |
18 | 18 | public function readConfig($action) |
19 | 19 | { |
20 | - $this->fieldsPresentation = $this->getConfigValue('fields_presentation') ? : []; |
|
21 | - $this->formTypes = $this->getConfigValue($action, 'form_types') ? : []; |
|
22 | - $this->validationRules = $this->getConfigValue($action, 'validation') ? : []; |
|
23 | - $this->functions = $this->getConfigValue($action, 'functions') ? : []; |
|
24 | - $this->defaults = $this->getConfigValue($action, 'defaults') ? : []; |
|
20 | + $this->fieldsPresentation = $this->getConfigValue('fields_presentation') ?: []; |
|
21 | + $this->formTypes = $this->getConfigValue($action, 'form_types') ?: []; |
|
22 | + $this->validationRules = $this->getConfigValue($action, 'validation') ?: []; |
|
23 | + $this->functions = $this->getConfigValue($action, 'functions') ?: []; |
|
24 | + $this->defaults = $this->getConfigValue($action, 'defaults') ?: []; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -4,8 +4,6 @@ |
||
4 | 4 | namespace Anavel\Crud\Abstractor\Eloquent\Traits; |
5 | 5 | |
6 | 6 | |
7 | -use Anavel\Crud\Contracts\Abstractor\Field; |
|
8 | - |
|
9 | 7 | trait ModelFields |
10 | 8 | { |
11 | 9 | protected $fieldsPresentation = []; |
@@ -55,7 +55,6 @@ |
||
55 | 55 | public function getSecondaryRelations(); |
56 | 56 | |
57 | 57 | /** |
58 | - * @param Model $relatedModel |
|
59 | 58 | * @return Relation |
60 | 59 | */ |
61 | 60 | public function setRelatedModel(\Illuminate\Database\Eloquent\Model $model); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function getEditFields($arrayKey = null) |
28 | 28 | { |
29 | - if(empty($arrayKey)) { |
|
29 | + if (empty($arrayKey)) { |
|
30 | 30 | $arrayKey = $this->name; |
31 | 31 | } |
32 | 32 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | $this->readConfig('edit'); |
50 | 50 | |
51 | - if (! empty($columns)) { |
|
51 | + if (!empty($columns)) { |
|
52 | 52 | foreach ($columns as $columnName => $column) { |
53 | 53 | if (in_array($columnName, $readOnly, true)) { |
54 | 54 | continue; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | |
59 | 59 | $config = [ |
60 | 60 | 'name' => $columnName, |
61 | - 'presentation' => $this->name . ' ' . ucfirst(transcrud($columnName)), |
|
61 | + 'presentation' => $this->name.' '.ucfirst(transcrud($columnName)), |
|
62 | 62 | 'form_type' => $formType, |
63 | 63 | 'no_validate' => true, |
64 | 64 | 'validation' => null, |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | ->setConfig($config) |
74 | 74 | ->get(); |
75 | 75 | |
76 | - if (! empty($result->id)) { |
|
76 | + if (!empty($result->id)) { |
|
77 | 77 | $field->setValue($result->getAttribute($columnName)); |
78 | 78 | } |
79 | 79 | |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function persist(array $relationArray = null) |
95 | 95 | { |
96 | - if (! empty($relationArray)) { |
|
96 | + if (!empty($relationArray)) { |
|
97 | 97 | $currentRelation = $this->eloquentRelation->getResults(); |
98 | - if (! empty($currentRelation)) { |
|
98 | + if (!empty($currentRelation)) { |
|
99 | 99 | $relationModel = $currentRelation; |
100 | 100 | } else { |
101 | 101 | $relationModel = $this->eloquentRelation->getRelated()->newInstance(); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $relationModel->setAttribute($fieldKey, $fieldValue); |
112 | 112 | } |
113 | 113 | |
114 | - if (! $shouldBeSkipped) { |
|
114 | + if (!$shouldBeSkipped) { |
|
115 | 115 | $relationModel->save(); |
116 | 116 | } |
117 | 117 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function persist(array $relationArray = null) |
30 | 30 | { |
31 | - if (! empty($relationArray)) { |
|
31 | + if (!empty($relationArray)) { |
|
32 | 32 | /** @var \ANavallaSuiza\Laravel\Database\Contracts\Repository\Repository $repo */ |
33 | 33 | $repo = $this->modelManager->getRepository(get_class($this->eloquentRelation->getRelated())); |
34 | 34 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $alreadyAssociated = $this->relatedModel->$relationName; |
38 | 38 | |
39 | 39 | $search = []; |
40 | - if (! empty($relationArray[$relatedKeyName])) { |
|
40 | + if (!empty($relationArray[$relatedKeyName])) { |
|
41 | 41 | $search = $relationArray[$relatedKeyName]; |
42 | 42 | } |
43 | 43 | $results = $repo->pushCriteria( |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $result->save(); |
54 | 54 | } |
55 | 55 | |
56 | - if (! $missing->isEmpty()) { |
|
56 | + if (!$missing->isEmpty()) { |
|
57 | 57 | foreach ($missing as $result) { |
58 | 58 | $result->$keyName = null; |
59 | 59 | $result->save(); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | { |
99 | 99 | $results = $this->eloquentRelation->getResults(); |
100 | 100 | |
101 | - if (! $results->isEmpty()) { |
|
101 | + if (!$results->isEmpty()) { |
|
102 | 102 | $values = []; |
103 | 103 | |
104 | 104 | foreach ($results as $result) { |
@@ -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; |
@@ -11,18 +11,18 @@ discard block |
||
11 | 11 | { |
12 | 12 | protected function handleField(Request $request, $item, array $fields, $groupName, $fieldName) |
13 | 13 | { |
14 | - $modelFolder = $this->slug . DIRECTORY_SEPARATOR; |
|
15 | - $basePath = base_path(DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR .config('anavel-crud.uploads_path')); |
|
16 | - $modelPath = $basePath . $modelFolder; |
|
14 | + $modelFolder = $this->slug.DIRECTORY_SEPARATOR; |
|
15 | + $basePath = base_path(DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.config('anavel-crud.uploads_path')); |
|
16 | + $modelPath = $basePath.$modelFolder; |
|
17 | 17 | $skip = null; |
18 | 18 | $requestValue = null; |
19 | - if (! empty($fields["{$fieldName}__delete"])) { |
|
19 | + if (!empty($fields["{$fieldName}__delete"])) { |
|
20 | 20 | //We never want to save this field, it doesn't exist in the DB |
21 | 21 | $skip = "{$fieldName}__delete"; |
22 | 22 | |
23 | 23 | |
24 | 24 | //If user wants to delete the existing file |
25 | - if (! empty($request->input("{$groupName}.{$fieldName}__delete"))) { |
|
25 | + if (!empty($request->input("{$groupName}.{$fieldName}__delete"))) { |
|
26 | 26 | $adapter = new Local($basePath); |
27 | 27 | $filesystem = new Filesystem($adapter); |
28 | 28 | if ($filesystem->has($item->$fieldName)) { |
@@ -39,22 +39,22 @@ discard block |
||
39 | 39 | ]; |
40 | 40 | } |
41 | 41 | } |
42 | - if ($request->hasFile($groupName .'.'.$fieldName)) { |
|
43 | - $fileName = uniqid() . '.' . $request->file($groupName .'.'.$fieldName)->getClientOriginalExtension(); |
|
42 | + if ($request->hasFile($groupName.'.'.$fieldName)) { |
|
43 | + $fileName = uniqid().'.'.$request->file($groupName.'.'.$fieldName)->getClientOriginalExtension(); |
|
44 | 44 | |
45 | 45 | |
46 | - $request->file($groupName .'.'.$fieldName)->move( |
|
46 | + $request->file($groupName.'.'.$fieldName)->move( |
|
47 | 47 | $modelPath, |
48 | 48 | $fileName |
49 | 49 | ); |
50 | 50 | |
51 | - $requestValue = $modelFolder . $fileName; |
|
52 | - } elseif (! empty($request->file($groupName .'.'.$fieldName)) && ! $request->file($groupName .'.'.$fieldName)->isValid()) { |
|
53 | - throw new \Exception($request->file($groupName .'.'.$fieldName)->getErrorMessage()); |
|
51 | + $requestValue = $modelFolder.$fileName; |
|
52 | + } elseif (!empty($request->file($groupName.'.'.$fieldName)) && !$request->file($groupName.'.'.$fieldName)->isValid()) { |
|
53 | + throw new \Exception($request->file($groupName.'.'.$fieldName)->getErrorMessage()); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | //Avoid losing the existing filename if the user doesn't change it: |
57 | - if (empty($requestValue) && (! empty($item->$fieldName))) { |
|
57 | + if (empty($requestValue) && (!empty($item->$fieldName))) { |
|
58 | 58 | $requestValue = $item->$fieldName; |
59 | 59 | } |
60 | 60 |