Passed
Push — master ( 3fee6c...158ed4 )
by Davide
03:58
created

ResponsiveGalleryController::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace DavideCasiraghi\ResponsiveGallery\Http\Controllers;
4
5
use Validator;
6
use Illuminate\Http\Request;
7
use DavideCasiraghi\ResponsiveGallery\Models\GalleryImage;
8
use DavideCasiraghi\ResponsiveGallery\Facades\ResponsiveGallery;
9
10
class ResponsiveGalleryController
11
{
12
    
13
    /***************************************************************************/
14
15
    /**
16
     * Display a listing of the resource.
17
     *
18
     * @return \Illuminate\Http\Response
19
     */
20
    public function index(Request $request)
21
    {
22
        $searchKeywords = $request->input('keywords');
23
24
        if ($searchKeywords) {
25
            $galleryImages = GalleryImage::orderBy('file_name')
26
                                    ->where('file_name', 'like', '%'.$request->input('keywords').'%')
27
                                    ->paginate(20);
28
        } else {
29
            $galleryImages = GalleryImage::orderBy('file_name')
30
                                    ->paginate(20);
31
        }
32
33
        return view('vendor.laravel-responsive-gallery.index', compact('galleryImages'))
34
                            ->with('i', (request()->input('page', 1) - 1) * 20)
35
                            ->with('searchKeywords', $searchKeywords);
36
    }
37
38
    /***************************************************************************/
39
40
    /**
41
     * Show the form for creating a new resource.
42
     *
43
     * @return \Illuminate\Http\Response
44
     */
45
    public function create()
46
    {
47
        return view('vendor.laravel-responsive-gallery.create');
48
    }
49
50
    /***************************************************************************/
51
52
    /**
53
     * Store a newly created resource in storage.
54
     *
55
     * @param  \Illuminate\Http\Request  $request
56
     * @return \Illuminate\Http\Response
57
     */
58
    public function store(Request $request)
59
    {
60
61
        // Validate form datas
62
        $validator = Validator::make($request->all(), [
63
                    'file_name' => 'required',
64
                ]);
65
        if ($validator->fails()) {
66
            return back()->withErrors($validator)->withInput();
67
        }
68
69
        $gallery_image = new GalleryImage();
70
        $gallery_image->file_name = $request->get('file_name');
71
        $gallery_image->description = $request->get('description');
72
        $gallery_image->alt = $request->get('alt');
73
        $gallery_image->video_link = $request->get('video_link');
74
75
        $gallery_image->save();
76
77
        return redirect()->route('responsive-gallery.index')
78
                            ->with('success', 'Image datas added succesfully');
79
    }
80
81
    /***************************************************************************/
82
83
    /**
84
     * Display the specified resource.
85
     *
86
     * @param  \App\Country  $country
0 ignored issues
show
Bug introduced by
The type App\Country 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...
87
     * @return \Illuminate\Http\Response
88
     */
89 1
    public function show($id = null)
90
    {
91 1
        $galleryImage = GalleryImage::find($id);
92 1
        return view('laravel-responsive-gallery::show', compact('galleryImage'));
93
    }
94
95
    /***************************************************************************/
96
97
    /**
98
     * Show the form for editing the specified resource.
99
     *
100
     * @param  \App\Country  $country
101
     * @return \Illuminate\Http\Response
102
     */
103
    public function edit($id = null)
104
    {
105
        $galleryImage = GalleryImage::find($id);
106
107
        return view('vendor.laravel-responsive-gallery.edit', compact('galleryImage'));
108
    }
109
110
    /***************************************************************************/
111
112
    /**
113
     * Update the specified resource in storage.
114
     *
115
     * @param  \Illuminate\Http\Request  $request
116
     * @param  \App\Country  $country
117
     * @return \Illuminate\Http\Response
118
     */
119
    public function update(Request $request, $id)
120
    {
121
        request()->validate([
122
                'file_name' => 'required',
123
            ]);
124
125
        $galleryImage = GalleryImage::find($id);
126
127
        $galleryImage->update($request->all());
128
129
        return redirect()->route('responsive-gallery.index')
130
                            ->with('success', 'Image datas updated succesfully');
131
    }
132
133
    /***************************************************************************/
134
135
    /**
136
     * Remove the specified resource from storage.
137
     *
138
     * @param  \App\Country  $country
139
     * @return \Illuminate\Http\Response
140
     */
141
    public function destroy($id)
142
    {
143
        $galleryImage = GalleryImage::find($id);
144
        $galleryImage->delete();
145
146
        return redirect()->route('responsive-gallery.index')
147
                            ->with('success', 'Image datas deleted succesfully');
148
    }
149
}
150