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

ServiceRepository::storeService()   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\ServiceRepositoryInterface;
6
use Adminetic\Website\Http\Requests\ServiceRequest;
7
use Adminetic\Website\Models\Admin\Service;
8
use Illuminate\Support\Facades\Cache;
9
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...
10
11
class ServiceRepository implements ServiceRepositoryInterface
12
{
13
    // Service Index
14
    public function indexService()
15
    {
16
        $services = config('adminetic.caching', true)
17
            ? (Cache::has('services') ? Cache::get('services') : Cache::rememberForever('services', function () {
18
                return Service::orderBy('position')->get();
19
            }))
20
            : Service::orderBy('position')->get();
21
22
        return compact('services');
23
    }
24
25
    // Service Create
26
    public function createService()
27
    {
28
        //
29
    }
30
31
    // Service Store
32
    public function storeService(ServiceRequest $request)
33
    {
34
        $service = Service::create($request->validated());
35
        $this->uploadImage($service);
36
    }
37
38
    // Service Show
39
    public function showService(Service $service)
40
    {
41
        return compact('service');
42
    }
43
44
    // Service Edit
45
    public function editService(Service $service)
46
    {
47
        return compact('service');
48
    }
49
50
    // Service Update
51
    public function updateService(ServiceRequest $request, Service $service)
52
    {
53
        $service->update($request->validated());
54
        $this->uploadImage($service);
55
    }
56
57
    // Service Destroy
58
    public function destroyService(Service $service)
59
    {
60
        $service->hardDelete('image');
61
        $service->delete();
62
    }
63
64
    // Upload Image
65
    protected function uploadImage(Service $service)
66
    {
67
        if (request()->icon_image) {
68
            $service->update([
69
                'icon_image' => request()->icon_image->store('website/service/image', 'public'),
70
            ]);
71
            $image = Image::make(request()->file('icon_image')->getRealPath());
72
            $image->save(public_path('storage/' . $service->icon_image));
73
        }
74
75
        if (request()->image) {
76
            $thumbnails = [
77
                'storage' => 'website/service/icon',
78
                'width' => '512',
79
                'height' => '512',
80
                'quality' => '80',
81
                'thumbnails' => [
82
                    [
83
                        'thumbnail-name' => 'small',
84
                        'thumbnail-width' => '150',
85
                        'thumbnail-height' => '100',
86
                        'thumbnail-quality' => '50',
87
                    ],
88
                ],
89
            ];
90
            $service->makeThumbnail('image', $thumbnails);
91
        }
92
    }
93
}
94