1 | <?php |
||||||
2 | |||||||
3 | namespace NovaThinKit\FeatureImage\Nova; |
||||||
4 | |||||||
5 | use Illuminate\Http\Request; |
||||||
6 | use Laravel\Nova\Fields\Image; |
||||||
7 | use NovaThinKit\FeatureImage\Models\WithFeatureImage; |
||||||
8 | |||||||
9 | trait HasFeatureImage |
||||||
10 | { |
||||||
11 | 10 | public function fieldFeatureImage(string $title = 'Feature Image', ?string $tag = null): Image |
|||||
12 | { |
||||||
13 | 10 | $model = $this->model(); |
|||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
14 | |||||||
15 | 10 | $attr = method_exists($model, 'featureImageKey') ? $model->featureImageKey($tag) : 'image'; |
|||||
16 | |||||||
17 | 10 | return Image::make($title, $attr) |
|||||
18 | 10 | ->rules(['mimes:jpeg,png', 'max:' . 1024 * 10]) |
|||||
19 | 10 | ->deletable(true) |
|||||
20 | 10 | ->store(function (Request $request, WithFeatureImage $model, string $attribute) use ($tag) { |
|||||
21 | 2 | return function () use ($request, $model, $attribute, $tag) { |
|||||
22 | 2 | if ($request->hasFile($attribute)) { |
|||||
23 | 2 | $model->$attribute = $model |
|||||
24 | 2 | ->featureImageManager($tag) |
|||||
25 | 2 | ->storeUploaded($request->file($attribute)); |
|||||
0 ignored issues
–
show
It seems like
$request->file($attribute) can also be of type Illuminate\Http\UploadedFile[] and array and null ; however, parameter $image of NovaThinKit\FeatureImage...anager::storeUploaded() does only seem to accept Illuminate\Http\UploadedFile , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
26 | 2 | $model->save(); |
|||||
0 ignored issues
–
show
The method
save() does not exist on NovaThinKit\FeatureImage\Models\WithFeatureImage . It seems like you code against a sub-type of said class. However, the method does not exist in NovaThinKit\Tests\Fixtures\AdvertisingDTO . Are you sure you never get one of those?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
27 | } |
||||||
28 | 2 | }; |
|||||
29 | 10 | }) |
|||||
30 | 10 | ->delete(function (Request $request, WithFeatureImage $model) use ($attr, $tag) { |
|||||
31 | 1 | if ($model->featureImageManager($tag)->delete()) { |
|||||
32 | 1 | $model->$attr = null; |
|||||
33 | } |
||||||
34 | |||||||
35 | 1 | return true; |
|||||
36 | 10 | }) |
|||||
37 | 10 | ->preview(function ($value, $disk, WithFeatureImage $model) use ($tag) { |
|||||
38 | 4 | return $model->featureImageManager($tag)->url('thumb'); |
|||||
39 | 10 | }) |
|||||
40 | 10 | ->thumbnail(function ($value, $disk, WithFeatureImage $model) use ($tag) { |
|||||
41 | 4 | return $model->featureImageManager($tag)->url('thumb'); |
|||||
42 | 10 | }) |
|||||
43 | 10 | ->download(function ($request, $model, $disk, $path) use ($tag) { |
|||||
0 ignored issues
–
show
The parameter
$path is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$disk is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||
44 | 1 | return $model->featureImageManager($tag)->download(); |
|||||
45 | 10 | }) |
|||||
46 | 10 | ->help('Image: jpg or png, ~1600x1200px. The script will automatically crop images'); |
|||||
47 | } |
||||||
48 | } |
||||||
49 |