Completed
Push — master ( 01f813...48da81 )
by Davide
03:11
created

ResponsiveGalleryController::edit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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