1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Validator; |
6
|
|
|
use App\Country; |
|
|
|
|
7
|
|
|
use App\Continent; |
|
|
|
|
8
|
|
|
use Illuminate\Http\Request; |
9
|
|
|
|
10
|
|
|
class CountryController extends Controller |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
/* Restrict the access to this resource just to logged in users */ |
13
|
|
|
public function __construct() |
14
|
|
|
{ |
15
|
|
|
$this->middleware('admin'); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/***************************************************************************/ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Display a listing of the resource. |
22
|
|
|
* @param \Illuminate\Http\Request $request |
23
|
|
|
* @return \Illuminate\Http\Response |
24
|
|
|
*/ |
25
|
|
|
public function index(Request $request) |
26
|
|
|
{ |
27
|
|
|
$continents = Continent::getContinents(); |
28
|
|
|
|
29
|
|
|
$searchKeywords = $request->input('keywords'); |
30
|
|
|
if ($searchKeywords) { |
31
|
|
|
$countries = Country::orderBy('name') |
32
|
|
|
->where('name', 'like', '%'.$request->input('keywords').'%') |
33
|
|
|
->paginate(20); |
34
|
|
|
} else { |
35
|
|
|
$countries = Country::orderBy('name') |
36
|
|
|
->paginate(20); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return view('countries.index', compact('countries')) |
40
|
|
|
->with('i', (request()->input('page', 1) - 1) * 20)->with('continents', $continents)->with('searchKeywords', $searchKeywords); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/***************************************************************************/ |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Show the form for creating a new resource. |
47
|
|
|
* |
48
|
|
|
* @return \Illuminate\Http\Response |
49
|
|
|
*/ |
50
|
|
|
public function create() |
51
|
|
|
{ |
52
|
|
|
$continents = Continent::getContinents(); |
53
|
|
|
|
54
|
|
|
return view('countries.create')->with('continents', $continents); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/***************************************************************************/ |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Store a newly created resource in storage. |
61
|
|
|
* |
62
|
|
|
* @param \Illuminate\Http\Request $request |
63
|
|
|
* @return \Illuminate\Http\Response |
64
|
|
|
*/ |
65
|
|
|
public function store(Request $request) |
66
|
|
|
{ |
67
|
|
|
|
68
|
|
|
// Validate form datas |
69
|
|
|
$validator = Validator::make($request->all(), [ |
70
|
|
|
'name' => 'required', |
71
|
|
|
'code' => 'required', |
72
|
|
|
'continent_id' => 'required', |
73
|
|
|
]); |
74
|
|
|
if ($validator->fails()) { |
75
|
|
|
return back()->withErrors($validator)->withInput(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$country = new Country(); |
79
|
|
|
$country->name = $request->get('name'); |
80
|
|
|
$country->code = $request->get('code'); |
81
|
|
|
$country->continent_id = $request->get('continent_id'); |
82
|
|
|
|
83
|
|
|
$country->save(); |
84
|
|
|
|
85
|
|
|
return redirect()->route('countries.index') |
86
|
|
|
->with('success', __('messages.country_added_successfully')); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/***************************************************************************/ |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Display the specified resource. |
93
|
|
|
* |
94
|
|
|
* @param \App\Country $country |
95
|
|
|
* @return \Illuminate\Http\Response |
96
|
|
|
*/ |
97
|
|
|
public function show(Country $country) |
98
|
|
|
{ |
99
|
|
|
return view('countries.show', compact('country')); |
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(Country $country) |
111
|
|
|
{ |
112
|
|
|
$continents = Continent::getContinents(); |
113
|
|
|
|
114
|
|
|
return view('countries.edit', compact('country'))->with('continents', $continents); |
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, Country $country) |
127
|
|
|
{ |
128
|
|
|
request()->validate([ |
129
|
|
|
'name' => 'required', |
130
|
|
|
'code' => 'required', |
131
|
|
|
'continent_id' => 'required', |
132
|
|
|
]); |
133
|
|
|
|
134
|
|
|
$country->update($request->all()); |
135
|
|
|
|
136
|
|
|
return redirect()->route('countries.index') |
137
|
|
|
->with('success', __('messages.country_updated_successfully')); |
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(Country $country) |
149
|
|
|
{ |
150
|
|
|
$country->delete(); |
151
|
|
|
|
152
|
|
|
return redirect()->route('countries.index') |
153
|
|
|
->with('success', __('messages.country_deleted_successfully')); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/***************************************************************************/ |
157
|
|
|
} |
158
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths