Completed
Push — master ( dc4f2a...373130 )
by Davide
05:12 queued 01:06
created

ResponsiveGalleryController::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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