Passed
Push — main ( 86a6dd...ec1f24 )
by PRATIK
03:12
created

GalleryRepository::storeGallery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Adminetic\Website\Repositories;
4
5
use Adminetic\Website\Contracts\GalleryRepositoryInterface;
6
use Adminetic\Website\Http\Requests\GalleryRequest;
7
use Adminetic\Website\Models\Admin\Gallery;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Cache;
10
use Intervention\Image\Facades\Image;
0 ignored issues
show
Bug introduced by
The type Intervention\Image\Facades\Image was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
class GalleryRepository implements GalleryRepositoryInterface
13
{
14
    // Gallery Index
15
    public function indexGallery()
16
    {
17
        $galleries = config('adminetic.caching', true)
18
            ? (Cache::has('galleries') ? Cache::get('galleries') : Cache::rememberForever('galleries', function () {
19
                return Gallery::latest()->get();
20
            }))
21
            : Gallery::latest()->get();
22
23
        return compact('galleries');
24
    }
25
26
    // Gallery Create
27
    public function createGallery()
28
    {
29
        //
30
    }
31
32
    // Gallery Store
33
    public function storeGallery(GalleryRequest $request)
34
    {
35
        $gallery = Gallery::create($request->validated());
36
        $this->multipleImageUpload($gallery);
37
    }
38
39
    // Gallery Show
40
    public function showGallery(Gallery $gallery)
41
    {
42
        return compact('gallery');
43
    }
44
45
    // Gallery Edit
46
    public function editGallery(Gallery $gallery)
47
    {
48
        return compact('gallery');
49
    }
50
51
    // Gallery Update
52
    public function updateGallery(GalleryRequest $request, Gallery $gallery)
53
    {
54
        $gallery->update($request->validated());
55
        $this->multipleImageUpload($gallery);
56
    }
57
58
    // Gallery Destroy
59
    public function destroyGallery(Gallery $gallery)
60
    {
61
        $gallery->delete();
62
    }
63
64
    // Destroy Gallery Image Upload
65
    public function destroyGalleryImage(Request $request)
66
    {
67
        $image = Image::findOrFail($request->id);
68
        $image->hardDelete('image');
69
        $image->delete();
70
71
        return response()->json(['msg' => 'Gallery Image Deleted Successfully']);
72
    }
73
74
    // multiple Image Upload
75
    protected function multipleImageUpload($gallery)
76
    {
77
        if (request()->has('images')) {
78
            $imageRequest = app(\Adminetic\Website\Http\Requests\GalleryImageRequest::class, ['gallery' => $gallery]);
79
            $imageRequest->validated();
80
            foreach (request()->images as $image) {
81
                $img = $gallery->images()->create([
82
                    'image' => $image,
83
                ]);
84
85
                // Multi Image Upload With Thumbnail
86
                $multiple = [
87
                    'storage' => 'website/gallery/' . validImageFolder($gallery->name, 'gallery'),
0 ignored issues
show
Bug introduced by
The function validImageFolder was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

87
                    'storage' => 'website/gallery/' . /** @scrutinizer ignore-call */ validImageFolder($gallery->name, 'gallery'),
Loading history...
88
                    'width' => '600',
89
                    'height' => '600',
90
                    'quality' => '70',
91
                    'image' => $image,
92
                    'thumbnails' => [
93
                        [
94
                            'thumbnail-name' => 'small',
95
                            'thumbnail-width' => '100',
96
                            'thumbnail-height' => '100',
97
                            'thumbnail-quality' => '30',
98
                        ],
99
                    ],
100
                ];
101
                $img->makeThumbnail('image', $multiple);
102
            }
103
        }
104
    }
105
}
106