SoftwareRepository::createSoftware()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
namespace Adminetic\Website\Repositories;
4
5
use Adminetic\Website\Contracts\SoftwareRepositoryInterface;
6
use Adminetic\Website\Http\Requests\SoftwareRequest;
7
use Adminetic\Website\Models\Admin\Software;
8
use Illuminate\Support\Facades\Cache;
9
10
class SoftwareRepository implements SoftwareRepositoryInterface
11
{
12
    // Software Index
13
    public function indexSoftware()
14
    {
15
        $software = config('adminetic.caching', true)
16
            ? (Cache::has('software') ? Cache::get('software') : Cache::rememberForever('software', function () {
17
                return Software::orderBy('position')->get();
18
            }))
19
            : Software::orderBy('position')->get();
20
21
        return compact('software');
22
    }
23
24
    // Software Create
25
    public function createSoftware()
26
    {
27
        //
28
    }
29
30
    // Software Store
31
    public function storeSoftware(SoftwareRequest $request)
32
    {
33
        $software = Software::create($request->validated());
34
        $this->uploadImage($software);
35
    }
36
37
    // Software Show
38
    public function showSoftware(Software $software)
39
    {
40
        return compact('software');
41
    }
42
43
    // Software Edit
44
    public function editSoftware(Software $software)
45
    {
46
        return compact('software');
47
    }
48
49
    // Software Update
50
    public function updateSoftware(SoftwareRequest $request, Software $software)
51
    {
52
        $software->update($request->validated());
53
        $this->uploadImage($software);
54
    }
55
56
    // Software Destroy
57
    public function destroySoftware(Software $software)
58
    {
59
        $software->delete();
60
    }
61
62
    // Upload Image
63
    private function uploadImage(Software $software)
64
    {
65
        if (request()->has('images')) {
66
            $software
67
                ->addFromMediaLibraryRequest(request()->images)
68
                ->toMediaCollection('images');
69
        }
70
        if (request()->has('banner')) {
71
            $software
72
                ->addFromMediaLibraryRequest(request()->banner)
73
                ->toMediaCollection('banner');
74
        }
75
    }
76
}
77