Completed
Push — master ( 171a12...804e02 )
by Davide
196:02 queued 191:44
created

ResponsiveGalleryController::index()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.6492

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 1
dl 0
loc 16
ccs 5
cts 11
cp 0.4545
crap 2.6492
rs 9.9
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
    public function __invoke()
13
    {
14
        //return ResponsiveGallery::getRandomQuote();
15
        $galleryImages = GalleryImage::orderBy('file_name')->paginate(20);
16
17
        return view('vendor.laravel-responsive-gallery.index', compact('galleryImages'))
18
                            ->with('i', (request()->input('page', 1) - 1) * 20);
19
    }
20
21
    /***************************************************************************/
22
23
    /**
24
     * Display a listing of the resource.
25
     *
26
     * @return \Illuminate\Http\Response
27
     */
28 1
    public function index(Request $request)
29
    {
30 1
        $searchKeywords = $request->input('keywords');
31
32 1
        if ($searchKeywords) {
33
            $galleryImages = GalleryImage::orderBy('file_name')
34
                                    ->where('file_name', 'like', '%'.$request->input('keywords').'%')
35
                                    ->paginate(20);
36
        } else {
37 1
            $galleryImages = GalleryImage::orderBy('file_name')
38 1
                                    ->paginate(20);
39
        }
40
41
        return view('vendor.laravel-responsive-gallery.index', compact('galleryImages'))
42
                            ->with('i', (request()->input('page', 1) - 1) * 20)
43
                            ->with('searchKeywords', $searchKeywords);
44
    }
45
46
    /***************************************************************************/
47
48
    /**
49
     * Show the form for creating a new resource.
50
     *
51
     * @return \Illuminate\Http\Response
52
     */
53
    public function create()
54
    {
55
        return view('vendor.laravel-responsive-gallery.create');
56
    }
57
58
    /***************************************************************************/
59
60
    /**
61
     * Store a newly created resource in storage.
62
     *
63
     * @param  \Illuminate\Http\Request  $request
64
     * @return \Illuminate\Http\Response
65
     */
66
    public function store(Request $request)
67
    {
68
69
            // Validate form datas
70
        $validator = Validator::make($request->all(), [
71
                    'file_name' => 'required',
72
                ]);
73
        if ($validator->fails()) {
74
            return back()->withErrors($validator)->withInput();
75
        }
76
77
        $gallery_image = new GalleryImage();
78
        $gallery_image->file_name = $request->get('file_name');
0 ignored issues
show
Bug introduced by
The property file_name does not seem to exist on DavideCasiraghi\Responsi...ery\Models\GalleryImage. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
79
        $gallery_image->description = $request->get('description');
0 ignored issues
show
Bug introduced by
The property description does not seem to exist on DavideCasiraghi\Responsi...ery\Models\GalleryImage. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
80
        $gallery_image->alt = $request->get('alt');
0 ignored issues
show
Bug introduced by
The property alt does not seem to exist on DavideCasiraghi\Responsi...ery\Models\GalleryImage. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
81
        $gallery_image->video_link = $request->get('video_link');
0 ignored issues
show
Bug introduced by
The property video_link does not seem to exist on DavideCasiraghi\Responsi...ery\Models\GalleryImage. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
82
83
        $gallery_image->save();
84
85
        return redirect()->route('responsive-gallery.index')
86
                            ->with('success', 'Image datas added succesfully');
87
    }
88
89
    /***************************************************************************/
90
91
    /**
92
     * Display the specified resource.
93
     *
94
     * @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...
95
     * @return \Illuminate\Http\Response
96
     */
97
    public function show(GalleryImage $galleryImage)
98
    {
99
        return view('vendor.laravel-responsive-gallery.show', compact('galleryImage'));
100
    }
101
102
    /***************************************************************************/
103
104
    /**
105
     * Show the form for editing the specified resource.
106
     *
107
     * @param  \App\Country  $country
108
     * @return \Illuminate\Http\Response
109
     */
110
    public function edit($id = null)
111
    {
112
        $galleryImage = GalleryImage::find($id);
113
114
        return view('vendor.laravel-responsive-gallery.edit', compact('galleryImage'));
115
    }
116
117
    /***************************************************************************/
118
119
    /**
120
     * Update the specified resource in storage.
121
     *
122
     * @param  \Illuminate\Http\Request  $request
123
     * @param  \App\Country  $country
124
     * @return \Illuminate\Http\Response
125
     */
126
    public function update(Request $request, $id)
127
    {
128
        request()->validate([
129
                'file_name' => 'required',
130
            ]);
131
132
        $galleryImage = GalleryImage::find($id);
133
134
        $galleryImage->update($request->all());
135
136
        return redirect()->route('responsive-gallery.index')
137
                            ->with('success', 'Image datas updated succesfully');
138
    }
139
140
    /***************************************************************************/
141
142
    /**
143
     * Remove the specified resource from storage.
144
     *
145
     * @param  \App\Country  $country
146
     * @return \Illuminate\Http\Response
147
     */
148
    public function destroy($id)
149
    {
150
        $galleryImage = GalleryImage::find($id);
151
        $galleryImage->delete();
152
153
        return redirect()->route('responsive-gallery.index')
154
                            ->with('success', 'Image datas deleted succesfully');
155
    }
156
}
157