1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DavideCasiraghi\LaravelEventsCalendar\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Validator; |
6
|
|
|
use App\EventCategory; |
|
|
|
|
7
|
|
|
use Illuminate\Support\Str; |
8
|
|
|
use Illuminate\Http\Request; |
9
|
|
|
use Illuminate\Support\Facades\DB; |
10
|
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization; |
|
|
|
|
11
|
|
|
|
12
|
|
|
class EventCategoryController extends Controller |
13
|
|
|
{ |
14
|
|
|
/* Restrict the access to this resource just to logged in users except show view */ |
15
|
|
|
public function __construct() |
16
|
|
|
{ |
17
|
|
|
$this->middleware('admin', ['except' => ['show']]); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Display a listing of the resource. |
22
|
|
|
* |
23
|
|
|
* @return \Illuminate\Http\Response |
24
|
|
|
*/ |
25
|
|
|
public function index() |
26
|
|
|
{ |
27
|
|
|
$eventCategories = EventCategory::latest()->paginate(20); |
28
|
|
|
|
29
|
|
|
// Countries available for translations |
30
|
|
|
$countriesAvailableForTranslations = LaravelLocalization::getSupportedLocales(); |
31
|
|
|
|
32
|
|
|
return view('eventCategories.index', compact('eventCategories')) |
33
|
|
|
->with('i', (request()->input('page', 1) - 1) * 20) |
34
|
|
|
->with('countriesAvailableForTranslations', $countriesAvailableForTranslations); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Show the form for creating a new resource. |
39
|
|
|
* |
40
|
|
|
* @return \Illuminate\Http\Response |
41
|
|
|
*/ |
42
|
|
|
public function create() |
43
|
|
|
{ |
44
|
|
|
return view('eventCategories.create'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Store a newly created resource in storage. |
49
|
|
|
* |
50
|
|
|
* @param \Illuminate\Http\Request $request |
51
|
|
|
* @return \Illuminate\Http\Response |
52
|
|
|
*/ |
53
|
|
|
public function store(Request $request) |
54
|
|
|
{ |
55
|
|
|
|
56
|
|
|
// Validate form datas |
57
|
|
|
$validator = Validator::make($request->all(), [ |
58
|
|
|
'name' => 'required', |
59
|
|
|
]); |
60
|
|
|
if ($validator->fails()) { |
61
|
|
|
return back()->withErrors($validator)->withInput(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$eventCategory = new EventCategory(); |
65
|
|
|
|
66
|
|
|
$this->saveOnDb($request, $eventCategory); |
67
|
|
|
|
68
|
|
|
return redirect()->route('eventCategories.index') |
69
|
|
|
->with('success', __('messages.category_added_successfully')); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Display the specified resource. |
74
|
|
|
* |
75
|
|
|
* @param \App\EventCategory $eventCategory |
76
|
|
|
* @return \Illuminate\Http\Response |
77
|
|
|
*/ |
78
|
|
|
public function show(EventCategory $eventCategory) |
79
|
|
|
{ |
80
|
|
|
return view('eventCategories.show', compact('eventCategory')); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Show the form for editing the specified resource. |
85
|
|
|
* |
86
|
|
|
* @param \App\EventCategory $eventCategory |
87
|
|
|
* @return \Illuminate\Http\Response |
88
|
|
|
*/ |
89
|
|
|
public function edit(EventCategory $eventCategory) |
90
|
|
|
{ |
91
|
|
|
return view('eventCategories.edit', compact('eventCategory')); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Update the specified resource in storage. |
96
|
|
|
* |
97
|
|
|
* @param \Illuminate\Http\Request $request |
98
|
|
|
* @param \App\EventCategory $eventCategory |
99
|
|
|
* @return \Illuminate\Http\Response |
100
|
|
|
*/ |
101
|
|
|
public function update(Request $request, EventCategory $eventCategory) |
102
|
|
|
{ |
103
|
|
|
request()->validate([ |
104
|
|
|
'name' => 'required', |
105
|
|
|
]); |
106
|
|
|
|
107
|
|
|
$this->saveOnDb($request, $eventCategory); |
108
|
|
|
|
109
|
|
|
return redirect()->route('eventCategories.index') |
110
|
|
|
->with('success', __('messages.category_updated_successfully')); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Remove the specified resource from storage. |
115
|
|
|
* |
116
|
|
|
* @param \App\EventCategory $eventCategory |
117
|
|
|
* @return \Illuminate\Http\Response |
118
|
|
|
*/ |
119
|
|
|
public function destroy(EventCategory $eventCategory) |
120
|
|
|
{ |
121
|
|
|
$eventCategory->delete(); |
122
|
|
|
|
123
|
|
|
return redirect()->route('eventCategories.index') |
124
|
|
|
->with('success', __('messages.category_deleted_successfully')); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
// ********************************************************************** |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Return the single event category datas by cat id. |
131
|
|
|
* |
132
|
|
|
* @param int $cat_id |
133
|
|
|
* @return \App\EventCategory |
134
|
|
|
*/ |
135
|
|
|
public function eventcategorydata($cat_id) |
136
|
|
|
{ |
137
|
|
|
$ret = DB::table('event_categories')->where('id', $cat_id)->first(); |
138
|
|
|
//dump($ret); |
139
|
|
|
|
140
|
|
|
return $ret; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
// ********************************************************************** |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Save/Update the record on DB. |
147
|
|
|
* |
148
|
|
|
* @param \Illuminate\Http\Request $request |
149
|
|
|
* @param \App\EventCategory $eventCategory |
150
|
|
|
* @return void |
151
|
|
|
*/ |
152
|
|
|
public function saveOnDb($request, $eventCategory) |
153
|
|
|
{ |
154
|
|
|
$eventCategory->name = $request->get('name'); |
155
|
|
|
$eventCategory->slug = Str::slug($eventCategory->name, '-'); |
156
|
|
|
|
157
|
|
|
$eventCategory->save(); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
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