1 | <?php |
||||||
2 | |||||||
3 | namespace DavideCasiraghi\PhpResponsiveRandomQuote\Http\Controllers; |
||||||
4 | |||||||
5 | use Illuminate\Http\Request; |
||||||
6 | use Illuminate\Support\Facades\App; |
||||||
7 | use DavideCasiraghi\PhpResponsiveRandomQuote\Models\Quote; |
||||||
8 | use Mcamara\LaravelLocalization\Facades\LaravelLocalization; |
||||||
9 | use DavideCasiraghi\PhpResponsiveRandomQuote\Facades\PhpResponsiveQuote; |
||||||
10 | |||||||
11 | class ResponsiveQuoteController |
||||||
12 | { |
||||||
13 | /** |
||||||
14 | * Display the specified resource. |
||||||
15 | * |
||||||
16 | * @param \Illuminate\Http\Request $request |
||||||
17 | * @return \Illuminate\Http\Response |
||||||
18 | */ |
||||||
19 | 3 | public function index(Request $request) |
|||||
20 | { |
||||||
21 | 3 | $searchKeywords = $request->input('keywords'); |
|||||
22 | //$searchCategory = $request->input('category_id'); |
||||||
23 | 3 | $countriesAvailableForTranslations = LaravelLocalization::getSupportedLocales(); |
|||||
24 | |||||||
25 | 3 | if ($searchKeywords) { |
|||||
26 | $quotes = Quote::orderBy('author') |
||||||
27 | ->where('author', 'like', '%'.$request->input('keywords').'%') |
||||||
28 | ->paginate(20); |
||||||
29 | } else { |
||||||
30 | 3 | $quotes = Quote::orderBy('author') |
|||||
31 | 3 | ->paginate(20); |
|||||
32 | } |
||||||
33 | |||||||
34 | 3 | return view('php-responsive-quote::quotes.index', compact('quotes')) |
|||||
35 | 3 | ->with('i', (request()->input('page', 1) - 1) * 20) |
|||||
36 | 3 | ->with('searchKeywords', $searchKeywords) |
|||||
37 | 3 | ->with('countriesAvailableForTranslations', $countriesAvailableForTranslations); |
|||||
38 | } |
||||||
39 | |||||||
40 | /***************************************************************************/ |
||||||
41 | |||||||
42 | /** |
||||||
43 | * Show the form for creating a new resource. |
||||||
44 | * |
||||||
45 | * @return \Illuminate\Http\Response |
||||||
46 | */ |
||||||
47 | 1 | public function create() |
|||||
48 | { |
||||||
49 | 1 | return view('php-responsive-quote::quotes.create'); |
|||||
50 | } |
||||||
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 | 1 | public function store(Request $request) |
|||||
61 | { |
||||||
62 | 1 | $quote = new Quote(); |
|||||
63 | 1 | $quote->author = $request->get('author'); |
|||||
64 | 1 | $quote->text = $request->get('text'); |
|||||
0 ignored issues
–
show
|
|||||||
65 | |||||||
66 | // Set the default language to edit the quote in English |
||||||
67 | 1 | App::setLocale('en'); |
|||||
68 | |||||||
69 | 1 | $this->saveOnDb($request, $quote); |
|||||
70 | |||||||
71 | 1 | return redirect()->route('php-responsive-quote.index') |
|||||
72 | 1 | ->with('success', 'Quote added succesfully'); |
|||||
73 | } |
||||||
74 | |||||||
75 | /***************************************************************************/ |
||||||
76 | |||||||
77 | /** |
||||||
78 | * Display the specified resource. |
||||||
79 | * |
||||||
80 | * @param int $quoteId |
||||||
81 | * @return \Illuminate\Http\Response |
||||||
82 | */ |
||||||
83 | 1 | public function show($quoteId = null) |
|||||
84 | { |
||||||
85 | 1 | $quote = Quote::find($quoteId); |
|||||
86 | |||||||
87 | 1 | return view('php-responsive-quote::quotes.show', compact('quote')); |
|||||
88 | } |
||||||
89 | |||||||
90 | /***************************************************************************/ |
||||||
91 | |||||||
92 | /** |
||||||
93 | * Show the form for editing the specified resource. |
||||||
94 | * |
||||||
95 | * @param int $quoteId |
||||||
96 | * @return \Illuminate\Http\Response |
||||||
97 | */ |
||||||
98 | 1 | public function edit($quoteId = null) |
|||||
99 | { |
||||||
100 | 1 | $quote = Quote::find($quoteId); |
|||||
101 | |||||||
102 | 1 | return view('php-responsive-quote::quotes.edit', compact('quote')); |
|||||
103 | } |
||||||
104 | |||||||
105 | /***************************************************************************/ |
||||||
106 | |||||||
107 | /** |
||||||
108 | * Update the specified resource in storage. |
||||||
109 | * |
||||||
110 | * @param \Illuminate\Http\Request $request |
||||||
111 | * @param int $quoteId |
||||||
112 | * @return \Illuminate\Http\Response |
||||||
113 | */ |
||||||
114 | 1 | public function update(Request $request, $quoteId) |
|||||
115 | { |
||||||
116 | 1 | $quote = Quote::find($quoteId); |
|||||
117 | |||||||
118 | // Set the default language to update the quote in English |
||||||
119 | 1 | App::setLocale('en'); |
|||||
120 | |||||||
121 | 1 | $this->saveOnDb($request, $quote); |
|||||
122 | |||||||
123 | 1 | return redirect()->route('php-responsive-quote.index') |
|||||
124 | 1 | ->with('success', 'Quote updated succesfully'); |
|||||
125 | } |
||||||
126 | |||||||
127 | /***************************************************************************/ |
||||||
128 | |||||||
129 | /** |
||||||
130 | * Remove the specified resource from storage. |
||||||
131 | * |
||||||
132 | * @param int $quoteId |
||||||
133 | * @return \Illuminate\Http\Response |
||||||
134 | */ |
||||||
135 | 1 | public function destroy($quoteId) |
|||||
136 | { |
||||||
137 | 1 | $quote = Quote::find($quoteId); |
|||||
138 | 1 | $quote->delete(); |
|||||
139 | |||||||
140 | 1 | return redirect()->route('php-responsive-quote.index') |
|||||
141 | 1 | ->with('success', 'Quote deleted succesfully'); |
|||||
142 | } |
||||||
143 | |||||||
144 | /***************************************************************************/ |
||||||
145 | |||||||
146 | /** |
||||||
147 | * Save the record on DB. |
||||||
148 | * @param \Illuminate\Http\Request $request |
||||||
149 | * @param \DavideCasiraghi\PhpResponsiveRandomQuote\Models\Quote $quote |
||||||
150 | * @return void |
||||||
151 | */ |
||||||
152 | 2 | public function saveOnDb($request, $quote) |
|||||
153 | { |
||||||
154 | 2 | $quote->translateOrNew('en')->text = $request->get('text'); |
|||||
155 | 2 | $quote->author = $request->get('author'); |
|||||
156 | 2 | $quote->save(); |
|||||
157 | 2 | } |
|||||
158 | |||||||
159 | /***************************************************************************/ |
||||||
160 | |||||||
161 | /** |
||||||
162 | * Display the specified resource. |
||||||
163 | * |
||||||
164 | * @return \Illuminate\Http\Response |
||||||
165 | */ |
||||||
166 | 1 | public function showRandomQuote() |
|||||
167 | { |
||||||
168 | 1 | $quote = PhpResponsiveQuote::getRandomQuote(); |
|||||
0 ignored issues
–
show
The method
getRandomQuote() does not exist on DavideCasiraghi\PhpRespo...ades\PhpResponsiveQuote . Since you implemented __callStatic , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
169 | |||||||
170 | // the view name is set in the - Service provider - boot - loadViewsFrom |
||||||
171 | 1 | return view('php-responsive-quote::show-random-quote', [ |
|||||
172 | 1 | 'quoteAuthor' => $quote['author'], |
|||||
173 | 1 | 'quoteText' => $quote['text'], |
|||||
174 | ]); |
||||||
175 | } |
||||||
176 | } |
||||||
177 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.