| 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
LogisticController | 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\Logistic;
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 LogisticController 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 | $logistics=Logistic::orderBy('id','desc')->paginate(35);
24 | return view('maintenance.logistic.index',['logistics'=>$logistics]);
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.logistic.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 | $logistic=new Logistic($request->all());
49 | $logistic->save();
50 |
51 | $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
52 | return redirect('maintenance/logistic/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:logistics'],
58 | ]);
59 | }
60 | protected function validatorUpdate(array $data)
61 | {
62 | return Validator::make($data, [
63 | 'name' => ['required', 'string', 'max:50'],
64 | ]);
65 | }
66 | /**
67 | * Display the specified resource.
68 | *
69 | * @param Logistic $logistic
70 | * @return Response
71 | */
72 | public function show(Logistic $logistic)
73 | {
74 | //
75 | }
76 |
77 | /**
78 | * Show the form for editing the specified resource.
79 | *
80 | * @param Logistic $logistic
81 | * @return Response
82 | */
83 | public function edit(Logistic $logistic)
84 | {
85 | if(!Gate::allows('物流公司-编辑')){ return redirect(url('/')); }
86 | return view('maintenance.logistic.edit',['logistic'=>$logistic]);
87 | }
88 |
89 | /**
90 | * Update the specified resource in storage.
91 | *
92 | * @param Request $request
93 | * @param Logistic $logistic
94 | * @return Response
95 | */
96 | public function update(Request $request, Logistic $logistic)
97 | {
98 | if(!Gate::allows('物流公司-编辑')){ return redirect(url('/')); }
99 | $this->validatorUpdate($request->all())->validate();
100 | $logistic->fill($request->all());
101 | $logistic->update();
102 | $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
103 | return redirect('maintenance/logistic/')->with('successTip',"成功修改物流公司“{$logistic['name']}”！");
104 | }
105 |
106 | /**
107 | * Remove the specified resource from storage.
108 | *
109 | * @param Logistic $logistic
110 | * @return array|Response
111 | * @throws Exception
112 | */
113 | public function destroy(Logistic $logistic)
114 | {
115 | if(!Gate::allows('物流公司-删除')){ return redirect(url('/')); }
116 | $this->log(__METHOD__,__FUNCTION__,$logistic->toJson(),Auth::user()['id']);
117 | $re=$logistic->delete();
118 | return ['success'=>$re];
119 | }
120 | }