|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\Http\Controllers\Operations; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Route; |
|
6
|
|
|
|
|
7
|
|
|
trait ForceDeleteRestoreOperation |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Define which routes are needed for this operation. |
|
11
|
|
|
* |
|
12
|
|
|
* @param string $segment Name of the current entity (singular). Used as first URL segment. |
|
13
|
|
|
* @param string $routeName Prefix of the route name. |
|
14
|
|
|
* @param string $controller Name of the current CrudController. |
|
15
|
|
|
*/ |
|
16
|
|
|
protected function setupForceDeleteRestoreRoutes($segment, $routeName, $controller) |
|
17
|
|
|
{ |
|
18
|
|
|
Route::delete($segment.'/{id}/forceDelete', [ |
|
19
|
|
|
'as' => $routeName.'.forceDelete', |
|
20
|
|
|
'uses' => $controller.'@forceDelete', |
|
21
|
|
|
'operation' => 'forceDelete', |
|
22
|
|
|
]); |
|
23
|
|
|
|
|
24
|
|
|
Route::post($segment.'/{id}/restore', [ |
|
25
|
|
|
'as' => $routeName.'.restore', |
|
26
|
|
|
'uses' => $controller.'@restore', |
|
27
|
|
|
'operation' => 'restore', |
|
28
|
|
|
]); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Add the default settings, buttons, etc that this operation needs. |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function setupForceDeleteDefaults() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->crud->allowAccess('forceDelete'); |
|
37
|
|
|
$this->crud->allowAccess('restore'); |
|
38
|
|
|
|
|
39
|
|
|
$this->crud->operation('forceDelete', function () { |
|
40
|
|
|
$this->crud->loadDefaultOperationSettingsFromConfig(); |
|
41
|
|
|
}); |
|
42
|
|
|
|
|
43
|
|
|
$this->crud->operation('list', function () { |
|
44
|
|
|
$this->crud->addButton('line', 'restore', 'view', 'crud::buttons.restore', 'end'); |
|
45
|
|
|
$this->crud->addButton('line', 'force-delete', 'view', 'crud::buttons.force-delete', 'end'); |
|
46
|
|
|
|
|
47
|
|
|
}); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param $id |
|
52
|
|
|
* @return mixed |
|
53
|
|
|
*/ |
|
54
|
|
|
public function forceDelete($id) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->crud->hasAccessOrFail('forceDelete'); |
|
57
|
|
|
|
|
58
|
|
|
return $this->crud->model->withTrashed()->find($id)->forceDelete(); |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param $id |
|
65
|
|
|
* @return mixed |
|
66
|
|
|
*/ |
|
67
|
|
|
public function restore($id) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->crud->hasAccessOrFail('restore'); |
|
70
|
|
|
|
|
71
|
|
|
return $this->crud->model->withTrashed()->find($id)->restore(); |
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|