|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Common; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use App\Model\Common\ChatScript; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
|
|
9
|
|
|
class ChatScriptController extends Controller |
|
10
|
|
|
{ |
|
11
|
|
|
public function __construct() |
|
12
|
|
|
{ |
|
13
|
|
|
$this->middleware('auth'); |
|
14
|
|
|
$this->middleware('admin'); |
|
15
|
|
|
|
|
16
|
|
|
$script = new ChatScript(); |
|
17
|
|
|
$this->script = $script; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Display a listing of the resource. |
|
22
|
|
|
* |
|
23
|
|
|
* @return \Illuminate\Http\Response |
|
24
|
|
|
*/ |
|
25
|
|
|
public function index() |
|
26
|
|
|
{ |
|
27
|
|
|
return view('themes.default1.common.chat.index'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function getScript() |
|
31
|
|
|
{ |
|
32
|
|
|
try { |
|
33
|
|
|
return \DataTables::of($this->script->get()) |
|
34
|
|
|
->addColumn('checkbox', function ($model) { |
|
35
|
|
|
return "<input type='checkbox' class='chat_checkbox' |
|
36
|
|
|
value=".$model->id.' name=select[] id=check>'; |
|
37
|
|
|
}) |
|
38
|
|
|
|
|
39
|
|
|
->addColumn('name', function ($model) { |
|
40
|
|
|
return $model->name; |
|
41
|
|
|
}) |
|
42
|
|
|
|
|
43
|
|
|
->addColumn('action', function ($model) { |
|
44
|
|
|
return '<a href='.url('chat/'.$model->id.'/edit'). |
|
45
|
|
|
" class='btn btn-sm btn-primary btn-xs'><i class='fa fa-edit' |
|
46
|
|
|
style='color:white;'> </i> Edit</a>"; |
|
47
|
|
|
}) |
|
48
|
|
|
->rawColumns(['checkbox', 'name', 'action']) |
|
49
|
|
|
->make(true); |
|
50
|
|
|
} catch (Exception $ex) { |
|
|
|
|
|
|
51
|
|
|
dd($ex->getLine()); |
|
52
|
|
|
|
|
53
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Show the form for creating a new resource. |
|
59
|
|
|
* |
|
60
|
|
|
* @return \Illuminate\Http\Response |
|
61
|
|
|
*/ |
|
62
|
|
|
public function create() |
|
63
|
|
|
{ |
|
64
|
|
|
return view('themes.default1.common.chat.create'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Store a newly created resource in storage. |
|
69
|
|
|
* |
|
70
|
|
|
* @param \Illuminate\Http\Request $request |
|
71
|
|
|
* |
|
72
|
|
|
* @return \Illuminate\Http\Response |
|
73
|
|
|
*/ |
|
74
|
|
|
public function store(Request $request) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->validate($request, [ |
|
77
|
|
|
'name' => 'required', |
|
78
|
|
|
'script'=> 'required', |
|
79
|
|
|
]); |
|
80
|
|
|
|
|
81
|
|
|
try { |
|
82
|
|
|
$this->script->fill($request->input())->save(); |
|
83
|
|
|
|
|
84
|
|
|
return redirect()->back()->with('success', \Lang::get('message.saved-successfully')); |
|
85
|
|
|
} catch (Exception $e) { |
|
86
|
|
|
Bugsnag::notifyException($ex); |
|
|
|
|
|
|
87
|
|
|
app('log')->useDailyFiles(storage_path().'/logs/laravel.log'); |
|
88
|
|
|
app('log')->error($ex->getMessage()); |
|
89
|
|
|
|
|
90
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Show the form for editing the specified resource. |
|
96
|
|
|
* |
|
97
|
|
|
* @param int $id |
|
98
|
|
|
* |
|
99
|
|
|
* @return \Illuminate\Http\Response |
|
100
|
|
|
*/ |
|
101
|
|
|
public function edit($id) |
|
102
|
|
|
{ |
|
103
|
|
|
$chat = $this->script->where('id', $id)->first(); |
|
104
|
|
|
|
|
105
|
|
|
return view('themes.default1.common.chat.edit', compact('chat')); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Update the specified resource in storage. |
|
110
|
|
|
* |
|
111
|
|
|
* @param \Illuminate\Http\Request $request |
|
112
|
|
|
* @param int $id |
|
113
|
|
|
* |
|
114
|
|
|
* @return \Illuminate\Http\Response |
|
115
|
|
|
*/ |
|
116
|
|
|
public function update(Request $request, $id) |
|
117
|
|
|
{ |
|
118
|
|
|
$this->validate($request, [ |
|
119
|
|
|
'name' => 'required', |
|
120
|
|
|
'script' => 'required', |
|
121
|
|
|
|
|
122
|
|
|
]); |
|
123
|
|
|
|
|
124
|
|
|
try { |
|
125
|
|
|
$script = $this->script->where('id', $id)->first(); |
|
126
|
|
|
$script->fill($request->input())->save(); |
|
127
|
|
|
|
|
128
|
|
|
return redirect()->back()->with('success', \Lang::get('message.updated-successfully')); |
|
129
|
|
|
} catch (\Exception $ex) { |
|
130
|
|
|
Bugsnag::notifyException($ex); |
|
131
|
|
|
|
|
132
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Remove the specified resource from storage. |
|
138
|
|
|
* |
|
139
|
|
|
* @param int $id |
|
140
|
|
|
* |
|
141
|
|
|
* @return \Illuminate\Http\Response |
|
142
|
|
|
*/ |
|
143
|
|
|
public function destroy(Request $request) |
|
144
|
|
|
{ |
|
145
|
|
|
try { |
|
146
|
|
|
$ids = $request->input('select'); |
|
147
|
|
|
if (!empty($ids)) { |
|
148
|
|
|
foreach ($ids as $id) { |
|
149
|
|
|
$script = $this->script->where('id', $id)->first(); |
|
150
|
|
|
if ($script) { |
|
151
|
|
|
$script->delete(); |
|
152
|
|
|
} else { |
|
153
|
|
|
echo "<div class='alert alert-danger alert-dismissable'> |
|
154
|
|
|
<i class='fa fa-ban'></i> |
|
155
|
|
|
<b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
|
156
|
|
|
/* @scrutinizer ignore-type */\Lang::get('message.failed').' |
|
157
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
158
|
|
|
'./* @scrutinizer ignore-type */\Lang::get('message.no-record').' |
|
159
|
|
|
</div>'; |
|
160
|
|
|
//echo \Lang::get('message.no-record') . ' [id=>' . $id . ']'; |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
echo "<div class='alert alert-success alert-dismissable'> |
|
164
|
|
|
<i class='fa fa-ban'></i> |
|
165
|
|
|
<b>"./* @scrutinizer ignore-type */\Lang::get('message.alert'). |
|
166
|
|
|
'!</b> './* @scrutinizer ignore-type */\Lang::get('message.success').' |
|
167
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
168
|
|
|
'./* @scrutinizer ignore-type */\Lang::get('message.deleted-successfully').' |
|
169
|
|
|
</div>'; |
|
170
|
|
|
} else { |
|
171
|
|
|
echo "<div class='alert alert-danger alert-dismissable'> |
|
172
|
|
|
<i class='fa fa-ban'></i> |
|
173
|
|
|
<b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
|
174
|
|
|
/* @scrutinizer ignore-type */\Lang::get('message.failed').' |
|
175
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
176
|
|
|
'./* @scrutinizer ignore-type */\Lang::get('message.select-a-row').' |
|
177
|
|
|
</div>'; |
|
178
|
|
|
} |
|
179
|
|
|
} catch (\Exception $e) { |
|
180
|
|
|
echo "<div class='alert alert-danger alert-dismissable'> |
|
181
|
|
|
<i class='fa fa-ban'></i> |
|
182
|
|
|
<b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
|
183
|
|
|
/* @scrutinizer ignore-type */\Lang::get('message.failed').' |
|
184
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
185
|
|
|
'.$e->getMessage().' |
|
186
|
|
|
</div>'; |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|