@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Thinktomorrow\Chief\Fields\Types; |
6 | 6 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | return $this; |
41 | 41 | } |
42 | 42 | |
43 | - return 'files['. ($this->values['name'] ?? $this->key()).']'; |
|
43 | + return 'files['.($this->values['name'] ?? $this->key()).']'; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | public function sluggifyName() |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $images = []; |
59 | 59 | $locale = $locale ?? app()->getLocale(); |
60 | 60 | |
61 | - $assets = $model->assetRelation->where('pivot.type', $this->key())->filter(function ($asset) use ($locale) { |
|
61 | + $assets = $model->assetRelation->where('pivot.type', $this->key())->filter(function($asset) use ($locale) { |
|
62 | 62 | return $asset->pivot->locale == $locale; |
63 | 63 | })->sortBy('pivot.order'); |
64 | 64 |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | if (isset(json_decode($file)->output)) { |
115 | 115 | $image_name = json_decode($file)->output->name; |
116 | 116 | $asset = app(AddAsset::class)->add($model, json_decode($file)->output->image, $type, $locale, $this->sluggifyFilename($image_name)); |
117 | - } else { |
|
117 | + }else { |
|
118 | 118 | if ($file instanceof UploadedFile) { |
119 | 119 | $image_name = $file->getClientOriginalName(); |
120 | 120 | $asset = app(AddAsset::class)->add($model, $file, $type, $locale, $this->sluggifyFilename($image_name)); |
@@ -122,16 +122,16 @@ discard block |
||
122 | 122 | // New files are passed with their filename (instead of their id) |
123 | 123 | // For new files we will replace the filename with the id. |
124 | 124 | if (false !== ($key = array_search($image_name, $files_order))) { |
125 | - $files_order[$key] = (string) $asset->id; |
|
125 | + $files_order[$key] = (string)$asset->id; |
|
126 | 126 | } |
127 | - } else { |
|
128 | - $file = Asset::find($file); |
|
127 | + }else { |
|
128 | + $file = Asset::find($file); |
|
129 | 129 | if ($file) { |
130 | 130 | if ($model->assetRelation()->where('asset_pivots.type', $type)->where('asset_pivots.locale', $locale)->get()->contains($file)) { |
131 | 131 | throw new DuplicateAssetException(); |
132 | 132 | } |
133 | 133 | |
134 | - $asset = app(AddAsset::class)->add($model, $file, $type, $locale); |
|
134 | + $asset = app(AddAsset::class)->add($model, $file, $type, $locale); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | } |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | */ |
145 | 145 | private function sluggifyFilename($filename): string |
146 | 146 | { |
147 | - $extension = substr($filename, strrpos($filename, '.') + 1); |
|
147 | + $extension = substr($filename, strrpos($filename, '.')+1); |
|
148 | 148 | $filename = substr($filename, 0, strrpos($filename, '.')); |
149 | - $filename = Str::slug($filename) . '.' . $extension; |
|
149 | + $filename = Str::slug($filename).'.'.$extension; |
|
150 | 150 | |
151 | 151 | return $filename; |
152 | 152 | } |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | if ($file instanceof UploadedFile && !$file->isValid()) { |
163 | 163 | if ($file->getError() == UPLOAD_ERR_INI_SIZE) { |
164 | 164 | throw new FileTooBigException( |
165 | - 'Cannot upload file because it exceeded the allowed upload_max_filesize: upload_max_filesize is smaller than post size. ' . |
|
166 | - 'upload_max_filesize: ' . (int)ini_get('upload_max_filesize') . 'MB, ' . |
|
167 | - 'post_max_size: ' . (int)(ini_get('post_max_size')) . 'MB' |
|
165 | + 'Cannot upload file because it exceeded the allowed upload_max_filesize: upload_max_filesize is smaller than post size. '. |
|
166 | + 'upload_max_filesize: '.(int)ini_get('upload_max_filesize').'MB, '. |
|
167 | + 'post_max_size: '.(int)(ini_get('post_max_size')).'MB' |
|
168 | 168 | ); |
169 | 169 | } |
170 | 170 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | foreach ($files as $locale => $_files) { |
180 | 180 | foreach ($_files as $action => $file) { |
181 | 181 | if (!in_array($action, $actions)) { |
182 | - throw new \InvalidArgumentException('A valid files entry should have a key of either ['.implode(',', $actions).']. Instead ' . $action . ' is given.'); |
|
182 | + throw new \InvalidArgumentException('A valid files entry should have a key of either ['.implode(',', $actions).']. Instead '.$action.' is given.'); |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | } |