@@ -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,28 +39,28 @@ discard block |
||
39 | 39 | ]; |
40 | 40 | } |
41 | 41 | } |
42 | - if ($request->hasFile($groupName .'.'.$fieldName)) { |
|
43 | - $fileName = pathinfo($request->file($groupName .'.'.$fieldName)->getClientOriginalName(), PATHINFO_FILENAME); |
|
44 | - $extension = pathinfo($request->file($groupName .'.'.$fieldName)->getClientOriginalName(), PATHINFO_EXTENSION); |
|
42 | + if ($request->hasFile($groupName.'.'.$fieldName)) { |
|
43 | + $fileName = pathinfo($request->file($groupName.'.'.$fieldName)->getClientOriginalName(), PATHINFO_FILENAME); |
|
44 | + $extension = pathinfo($request->file($groupName.'.'.$fieldName)->getClientOriginalName(), PATHINFO_EXTENSION); |
|
45 | 45 | |
46 | - $fileName = uniqid() . '_' . slugify($fileName); |
|
47 | - if (! empty($extension)) { |
|
48 | - $fileName .= '.' . $extension; |
|
46 | + $fileName = uniqid().'_'.slugify($fileName); |
|
47 | + if (!empty($extension)) { |
|
48 | + $fileName .= '.'.$extension; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | |
52 | - $request->file($groupName .'.'.$fieldName)->move( |
|
52 | + $request->file($groupName.'.'.$fieldName)->move( |
|
53 | 53 | $modelPath, |
54 | 54 | $fileName |
55 | 55 | ); |
56 | 56 | |
57 | - $requestValue = $modelFolder . $fileName; |
|
58 | - } elseif (! empty($request->file($groupName .'.'.$fieldName)) && ! $request->file($groupName .'.'.$fieldName)->isValid()) { |
|
59 | - throw new \Exception($request->file($groupName .'.'.$fieldName)->getErrorMessage()); |
|
57 | + $requestValue = $modelFolder.$fileName; |
|
58 | + } elseif (!empty($request->file($groupName.'.'.$fieldName)) && !$request->file($groupName.'.'.$fieldName)->isValid()) { |
|
59 | + throw new \Exception($request->file($groupName.'.'.$fieldName)->getErrorMessage()); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | //Avoid losing the existing filename if the user doesn't change it: |
63 | - if (empty($requestValue) && (! empty($item->$fieldName))) { |
|
63 | + if (empty($requestValue) && (!empty($item->$fieldName))) { |
|
64 | 64 | $requestValue = $item->$fieldName; |
65 | 65 | } |
66 | 66 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | |
18 | 18 | public function apply($model, Repository $repository) |
19 | 19 | { |
20 | - $query = $model->where(function ($query) use ($repository) { |
|
20 | + $query = $model->where(function($query) use ($repository) { |
|
21 | 21 | $firstColumn = array_shift($this->columns); |
22 | 22 | |
23 | 23 | if (strpos($firstColumn, '.')) { |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | $columnRelation = explode('.', $column); |
44 | 44 | |
45 | 45 | if ($or) { |
46 | - $query->orWhereHas($columnRelation[0], function ($subquery) use ($columnRelation) { |
|
46 | + $query->orWhereHas($columnRelation[0], function($subquery) use ($columnRelation) { |
|
47 | 47 | $subquery->where($columnRelation[1], 'LIKE', '%'.$this->queryString.'%'); |
48 | 48 | }); |
49 | 49 | } else { |
50 | - $query->whereHas($columnRelation[0], function ($subquery) use ($columnRelation) { |
|
50 | + $query->whereHas($columnRelation[0], function($subquery) use ($columnRelation) { |
|
51 | 51 | $subquery->where($columnRelation[1], 'LIKE', '%'.$this->queryString.'%'); |
52 | 52 | }); |
53 | 53 | } |