Delete.php
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace App\Admin\Rewrite\Grid\Actions;
use Encore\Admin\Actions\Response;
use App\Admin\Rewrite\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class Delete extends RowAction
{
/**
* @return array|null|string
*/
public function name()
{
return __('admin.delete');
}
/**
* @param Model $model
*
* @return Response
*/
public function handle(Model $model)
{
$trans = [
'failed' => trans('admin.delete_failed'),
'succeeded' => trans('admin.delete_succeeded'),
];
try {
DB::transaction(function () use ($model) {
$model->delete();
});
} catch (\Exception $exception) {
return $this->response()->error("{$trans['failed']} : {$exception->getMessage()}");
}
return $this->response()->success($trans['succeeded'])->refresh();
}
/**
* @return void
*/
public function dialog()
{
$this->question(trans('admin.delete_confirm'), '', ['confirmButtonColor' => '#d33']);
}
}