|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\License; |
|
4
|
|
|
|
|
5
|
|
|
use App\Model\License\licenseType; |
|
6
|
|
|
use App\Model\Product\Product; |
|
7
|
|
|
use Bugsnag; |
|
8
|
|
|
use Illuminate\Http\Request; |
|
9
|
|
|
|
|
10
|
|
|
class LicenseSettingsController extends LicensePermissionsController |
|
11
|
|
|
{ |
|
12
|
|
|
private $licenseType; |
|
13
|
|
|
|
|
14
|
|
|
public function __construct() |
|
15
|
|
|
{ |
|
16
|
|
|
$this->middleware('auth'); |
|
17
|
|
|
$this->middleware('admin'); |
|
18
|
|
|
|
|
19
|
|
|
$licenseType = new LicenseType(); |
|
20
|
|
|
$this->licenseType = $licenseType; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Display a listing of the resource. |
|
25
|
|
|
* |
|
26
|
|
|
* @return \Illuminate\Http\Response |
|
27
|
|
|
*/ |
|
28
|
|
|
public function index() |
|
29
|
|
|
{ |
|
30
|
|
|
return view('themes.default1.licence.index'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/* |
|
34
|
|
|
* Get All the categories |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getLicenseTypes() |
|
37
|
|
|
{ |
|
38
|
|
|
try { |
|
39
|
|
|
$allTypes = $this->licenseType->select('id', 'name')->get(); |
|
40
|
|
|
|
|
41
|
|
|
return \DataTables::of($allTypes) |
|
42
|
|
|
->addColumn('checkbox', function ($model) { |
|
43
|
|
|
return "<input type='checkbox' class='type_checkbox' |
|
44
|
|
|
value=".$model->id.' name=select[] id=check>'; |
|
45
|
|
|
}) |
|
46
|
|
|
->addColumn('type_name', function ($model) { |
|
47
|
|
|
return ucfirst($model->name); |
|
48
|
|
|
}) |
|
49
|
|
|
->addColumn('action', function ($model) { |
|
50
|
|
|
return "<p><button data-toggle='modal' |
|
51
|
|
|
data-id=".$model->id." data-name= '$model->name' |
|
52
|
|
|
class='btn btn-sm btn-primary btn-xs editType'><i class='fa fa-edit' |
|
53
|
|
|
style='color:white;'> </i> Edit</button> </p>"; |
|
54
|
|
|
}) |
|
55
|
|
|
->rawColumns(['checkbox', 'type_name', 'action']) |
|
56
|
|
|
->make(true); |
|
57
|
|
|
} catch (\Exception $ex) { |
|
58
|
|
|
Bugsnag::notifyException($ex); |
|
59
|
|
|
|
|
60
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Store a newly created resource in storage. |
|
66
|
|
|
* |
|
67
|
|
|
* @param \Illuminate\Http\Request $request |
|
68
|
|
|
* |
|
69
|
|
|
* @return \Illuminate\Http\Response |
|
70
|
|
|
*/ |
|
71
|
|
|
public function store(Request $request) |
|
72
|
|
|
{ |
|
73
|
|
|
try { |
|
74
|
|
|
$productType = $this->licenseType->fill($request->input())->save(); |
|
75
|
|
|
|
|
76
|
|
|
return redirect()->back()->with('success', \Lang::get('message.saved-successfully')); |
|
|
|
|
|
|
77
|
|
|
} catch (\Exception $ex) { |
|
78
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function update(Request $request, $id) |
|
83
|
|
|
{ |
|
84
|
|
|
try { |
|
85
|
|
|
$type_name = $request->input('name'); |
|
86
|
|
|
$type = $this->licenseType->where('id', $id)->update(['name' =>$type_name]); |
|
87
|
|
|
|
|
88
|
|
|
return redirect()->back()->with('success', \Lang::get('message.updated-successfully')); |
|
89
|
|
|
} catch (\Exception $ex) { |
|
90
|
|
|
Bugsnag::notifyException($ex); |
|
91
|
|
|
|
|
92
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Remove the specified resource from storage. |
|
100
|
|
|
* |
|
101
|
|
|
* @param int $id |
|
102
|
|
|
* |
|
103
|
|
|
* @return \Illuminate\Http\Response |
|
104
|
|
|
*/ |
|
105
|
|
|
public function destroy(Request $request) |
|
106
|
|
|
{ |
|
107
|
|
|
try { |
|
108
|
|
|
$ids = $request->input('select'); |
|
109
|
|
|
if (!empty($ids)) { |
|
110
|
|
|
foreach ($ids as $id) { |
|
111
|
|
|
$type = $this->licenseType->where('id', $id)->first(); |
|
112
|
|
|
if ($type) { |
|
113
|
|
|
$type->delete(); |
|
114
|
|
|
} else { |
|
115
|
|
|
echo "<div class='alert alert-danger alert-dismissable'> |
|
116
|
|
|
<i class='fa fa-ban'></i> |
|
117
|
|
|
<b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
|
118
|
|
|
/* @scrutinizer ignore-type */\Lang::get('message.failed').' |
|
119
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
120
|
|
|
'./* @scrutinizer ignore-type */\Lang::get('message.no-record').' |
|
121
|
|
|
</div>'; |
|
122
|
|
|
//echo \Lang::get('message.no-record') . ' [id=>' . $id . ']'; |
|
123
|
|
|
} |
|
124
|
|
|
echo "<div class='alert alert-success alert-dismissable'> |
|
125
|
|
|
<i class='fa fa-ban'></i> |
|
126
|
|
|
|
|
127
|
|
|
<b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
|
128
|
|
|
/* @scrutinizer ignore-type */\Lang::get('message.success').' |
|
129
|
|
|
|
|
130
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
131
|
|
|
'./* @scrutinizer ignore-type */\Lang::get('message.deleted-successfully').' |
|
132
|
|
|
</div>'; |
|
133
|
|
|
} |
|
134
|
|
|
} else { |
|
135
|
|
|
echo "<div class='alert alert-danger alert-dismissable'> |
|
136
|
|
|
<i class='fa fa-ban'></i> |
|
137
|
|
|
<b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
|
138
|
|
|
/* @scrutinizer ignore-type */\Lang::get('message.failed').' |
|
139
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
140
|
|
|
'./* @scrutinizer ignore-type */\Lang::get('message.select-a-row').' |
|
141
|
|
|
</div>'; |
|
142
|
|
|
//echo \Lang::get('message.select-a-row'); |
|
143
|
|
|
} |
|
144
|
|
|
} catch (\Exception $e) { |
|
145
|
|
|
echo "<div class='alert alert-danger alert-dismissable'> |
|
146
|
|
|
<i class='fa fa-ban'></i> |
|
147
|
|
|
<b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
|
148
|
|
|
/* @scrutinizer ignore-type */ |
|
149
|
|
|
\Lang::get('message.failed').' |
|
150
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
151
|
|
|
'.$e->getMessage().' |
|
152
|
|
|
</div>'; |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|