| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 9 | CRAP | 0.00% covered (danger) | 0.00% | 0 / 28
QualityLabelController | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 9 | 240.00 | 0.00% covered (danger) | 0.00% | 0 / 28
index | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.00 | 0.00% covered (danger) | 0.00% | 0 / 3
create | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.00 | 0.00% covered (danger) | 0.00% | 0 / 2
store | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.00 | 0.00% covered (danger) | 0.00% | 0 / 6
validatorCreate | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 2
validatorUpdate | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 2
show | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 1
edit | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.00 | 0.00% covered (danger) | 0.00% | 0 / 2
update | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.00 | 0.00% covered (danger) | 0.00% | 0 / 6
destroy | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.00 | 0.00% covered (danger) | 0.00% | 0 / 4

1 | <?php
2 |
3 | namespace App\Http\Controllers;
4 |
5 | use App\QualityLabel;
6 | use Exception;
7 | use Illuminate\Http\Request;
8 | use Illuminate\Http\Response;
9 | use Illuminate\Support\Facades\Auth;
10 | use Illuminate\Support\Facades\Gate;
11 | use Illuminate\Support\Facades\Validator;
12 |
13 | class QualityLabelController extends Controller
14 | {
15 | /**
16 | * Display a listing of the resource.
17 | *
18 | * @return Response
19 | */
20 | public function index()
21 | {
22 | if(!Gate::allows('品质标签-查询')){ return redirect(url('/')); }
23 | $qualityLabels=QualityLabel::orderBy('id','desc')->paginate(35);
24 | return view('maintenance.qualityLabel.index',['qualityLabels'=>$qualityLabels]);
25 | }
26 |
27 | /**
28 | * Show the form for creating a new resource.
29 | *
30 | * @return Response
31 | */
32 | public function create()
33 | {
34 | if(!Gate::allows('品质标签-录入')){ return redirect(url('/')); }
35 | return view('maintenance.qualityLabel.create');
36 | }
37 |
38 | /**
39 | * Store a newly created resource in storage.
40 | *
41 | * @param Request $request
42 | * @return Response
43 | */
44 | public function store(Request $request)
45 | {
46 | if(!Gate::allows('品质标签-录入')){ return redirect(url('/')); }
47 | $this->validatorCreate($request->all())->validate();
48 | $qualityLabel=new QualityLabel($request->all());
49 | $qualityLabel->save();
50 |
51 | $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
52 | return redirect('maintenance/qualityLabel/create')->with('successTip',"成功录入品质标签“{$request->input('name')}”");
53 | }
54 | protected function validatorCreate(array $data)
55 | {
56 | return Validator::make($data, [
57 | 'name' => ['required', 'string', 'max:50', 'unique:quality_labels'],
58 | ]);
59 | }
60 | protected function validatorUpdate(array $data)
61 | {
62 | return Validator::make($data, [
63 | 'name' => ['required', 'string', 'max:50'],
64 | ]);
65 | }
66 |
67 | /**
68 | * Display the specified resource.
69 | *
70 | * @param QualityLabel $qualityLabel
71 | * @return void
72 | */
73 | public function show(QualityLabel $qualityLabel)
74 | {
75 | //
76 | }
77 |
78 | /**
79 | * Show the form for editing the specified resource.
80 | *
81 | * @param QualityLabel $qualityLabel
82 | * @return Response
83 | */
84 | public function edit(QualityLabel $qualityLabel)
85 | {
86 | if(!Gate::allows('品质标签-编辑')){ return redirect(url('/')); }
87 | return view('maintenance.qualityLabel.edit',['qualityLabel'=>$qualityLabel]);
88 | }
89 |
90 | /**
91 | * Update the specified resource in storage.
92 | *
93 | * @param Request $request
94 | * @param QualityLabel $qualityLabel
95 | * @return Response
96 | */
97 | public function update(Request $request, QualityLabel $qualityLabel)
98 | {
99 | if(!Gate::allows('品质标签-编辑')){ return redirect(url('/')); }
100 | $this->validatorUpdate($request->all())->validate();
101 | $qualityLabel->fill($request->all());
102 | $qualityLabel->update();
103 | $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
104 | return redirect('maintenance/qualityLabel/')->with('successTip',"成功修改品质标签“{$qualityLabel['name']}”！");
105 | }
106 |
107 | /**
108 | * Remove the specified resource from storage.
109 | *
110 | * @param QualityLabel $qualityLabel
111 | * @return array|Response
112 | * @throws Exception
113 | */
114 | public function destroy(QualityLabel $qualityLabel)
115 | {
116 | if(!Gate::allows('品质标签-删除')){ return redirect(url('/')); }
117 | $this->log(__METHOD__,__FUNCTION__,$qualityLabel->toJson(),Auth::user()['id']);
118 | $re=$qualityLabel->delete();
119 | return ['success'=>$re];
120 | }
121 | }