1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Crocodicstudio\Crudbooster\controllers\CBController; |
4
|
|
|
|
5
|
|
|
use Crocodicstudio\Crudbooster\CBCoreModule\DataRemover; |
6
|
|
|
use Illuminate\Support\Facades\Request; |
7
|
|
|
use Illuminate\Support\Facades\Storage; |
8
|
|
|
use Crocodicstudio\Crudbooster\helpers\CRUDBooster; |
9
|
|
|
|
10
|
|
|
trait Deleter |
11
|
|
|
{ |
12
|
|
|
public function getDelete($id) |
13
|
|
|
{ |
14
|
|
|
$this->genericLoader(); |
|
|
|
|
15
|
|
|
(new DataRemover($this))->doDeleteWithHook([$id]); |
16
|
|
|
$url = request('return_url') ?: Request::server('HTTP_REFERER'); |
17
|
|
|
CRUDBooster::redirect($url, cbTrans('alert_delete_data_success'), 'success'); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function postActionSelected() |
21
|
|
|
{ |
22
|
|
|
$this->genericLoader(); |
23
|
|
|
$selectedIds = request('checkbox'); |
24
|
|
|
$btnName = request('button_name'); |
25
|
|
|
if (! $selectedIds) { |
26
|
|
|
backWithMsg(cbTrans('at_least_one_row'), 'warning'); |
27
|
|
|
} |
28
|
|
|
if ($btnName == 'delete') { |
29
|
|
|
(new DataRemover($this))->doDeleteWithHook($selectedIds); |
30
|
|
|
backWithMsg(cbTrans('alert_delete_selected_success')); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return $this->_redirectBackWithMsg($btnName, $selectedIds); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param $button_name |
38
|
|
|
* @param $id_selected |
39
|
|
|
* @return null |
40
|
|
|
*/ |
41
|
|
|
private function _redirectBackWithMsg($button_name, $id_selected) |
42
|
|
|
{ |
43
|
|
|
$action = ucwords(str_replace(['-', '_'], ' ', $button_name)); |
44
|
|
|
$type = 'success'; |
45
|
|
|
$message = cbTrans('alert_action', ['action' => $action]); |
46
|
|
|
|
47
|
|
|
if ($this->actionButtonSelected($id_selected, $button_name) === false) { |
|
|
|
|
48
|
|
|
$message = ! empty($this->alert['message']) ? $this->alert['message'] : 'Error'; |
49
|
|
|
$type = ! empty($this->alert['type']) ? $this->alert['type'] : 'danger'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
backWithMsg($message, $type); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getDeleteImage() |
56
|
|
|
{ |
57
|
|
|
$this->genericLoader(); |
58
|
|
|
$id = (int) request('id'); |
59
|
|
|
$column = request('column'); |
60
|
|
|
|
61
|
|
|
$row = $this->findRow($id)->first(); |
|
|
|
|
62
|
|
|
$file = $row->{$column}; |
63
|
|
|
|
64
|
|
|
Storage::delete($file); |
65
|
|
|
|
66
|
|
|
$this->findRow($id)->update([$column => null]); |
67
|
|
|
|
68
|
|
|
event('cb.imageDeleted', [$this->table, compact('id', 'column', 'file'), YmdHis(), cbUser()]); |
69
|
|
|
|
70
|
|
|
backWithMsg(cbTrans('alert_delete_data_success')); |
71
|
|
|
} |
72
|
|
|
} |