Completed
Push — master ( 53bb8a...166f04 )
by Davide
04:44 queued 10s
created

ResponsiveGalleryController::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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