1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bantenprov\Workflow\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use Bantenprov\Workflow\Facades\Workflow; |
8
|
|
|
use Bantenprov\Workflow\Models\WorkflowTransition; |
9
|
|
|
use Bantenprov\Workflow\Models\WorkflowState; |
10
|
|
|
use That0n3guy\Transliteration; |
11
|
|
|
|
12
|
|
|
class WorkflowStateController extends Controller |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
public function index() |
16
|
|
|
{ |
17
|
|
|
$states = WorkflowState::paginate(10); |
18
|
|
|
|
19
|
|
|
return view('workflow.state.index',compact('states')); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function create() |
23
|
|
|
{ |
24
|
|
|
return view('workflow.state.create'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
View Code Duplication |
public function store(Request $request) |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$name = \Transliteration::clean_filename(strtolower($request->label)); |
30
|
|
|
$label = $request->label; |
31
|
|
|
|
32
|
|
|
try |
33
|
|
|
{ |
34
|
|
|
WorkflowState::create([ |
35
|
|
|
'name' => $name, |
36
|
|
|
'label' => $label, |
37
|
|
|
]); |
38
|
|
|
} |
39
|
|
|
catch(\Illuminate\Database\QueryException $e){ |
|
|
|
|
40
|
|
|
// do what you want here with $e->getMessage(); |
41
|
|
|
return redirect()->route('state')->with('message', 'Error'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return redirect()->route('state')->with('message', 'Add data success'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function show($id) |
48
|
|
|
{ |
49
|
|
|
// |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function edit($id) |
53
|
|
|
{ |
54
|
|
|
$state = WorkflowState::where('id',$id)->first(); |
55
|
|
|
|
56
|
|
|
return view('workflow.state.edit',['state' => $state]); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
View Code Duplication |
public function update(Request $request, $id) |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$name = \Transliteration::clean_filename(strtolower($request->label)); |
62
|
|
|
$label = $request->label; |
63
|
|
|
|
64
|
|
|
try |
65
|
|
|
{ |
66
|
|
|
WorkflowState::where('id',$id)->update(['label' => $label, 'name' => $name]); |
67
|
|
|
} |
68
|
|
|
catch(\Illuminate\Database\QueryException $e){ |
|
|
|
|
69
|
|
|
// do what you want here with $e->getMessage(); |
70
|
|
|
return redirect()->route('state')->with('message', 'Error'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return redirect()->route('state')->with('message', 'Update data success'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function Active($id){ |
77
|
|
|
WorkflowState::where('id',$id)->update(['status' => 1]); |
78
|
|
|
|
79
|
|
|
return redirect()->back(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function DeActive($id){ |
83
|
|
|
WorkflowState::where('id',$id)->update(['status' => 0]); |
84
|
|
|
|
85
|
|
|
return redirect()->back(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function destroy($id) |
89
|
|
|
{ |
90
|
|
|
// |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.