paginate(25); return view('maintenance.owner.index',['owners'=>$owners]); } public function create() { if(!Gate::allows('货主-录入')){ return redirect(url('/')); } return view('maintenance.owner.create'); } /** * Store a newly created resource in storage. * * @param Request $request * @return string */ public function store(Request $request) { if(!Gate::allows('货主-录入')){ return redirect(url('/')); } $this->validatorCreate($request->all())->validate(); $owner=new Owner($request->all()); $owner->save(); $authority=new Authority([ 'name'=>"_{$owner['id']}", 'alias_name'=>"(货主:{$owner['name']})", 'remark'=>"(key: _{$owner['id']})", ]); $authority->save(); $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']); return redirect('maintenance/owner/create')->with('successTip',$request->input('name')??''); } protected function validatorCreate(array $data) { return Validator::make($data, [ 'code' => ['required', 'string', 'max:50', 'unique:owners'], 'name' => ['required', 'string', 'max:50'], ]); } protected function validatorUpdate(array $data) { return Validator::make($data, [ 'name' => ['required', 'string', 'max:50'], ]); } /** * Display the specified resource. * * @param Owner $owner * @return Response */ public function show(Owner $owner) { // } /** * Show the form for editing the specified resource. * * @param Owner $owner * @return Response */ public function edit(Owner $owner) { if(!Gate::allows('货主-编辑')){ return redirect(url('/')); } return view('maintenance.owner.edit',['owner'=>$owner]); } /** * Update the specified resource in storage. * * @param Request $request * @param Owner $owner * @return Response */ public function update(Request $request, Owner $owner) { if(!Gate::allows('货主-编辑')){ return redirect(url('/')); } $this->validatorUpdate($request->all())->validate(); $owner->fill($request->all()); $owner->update(); $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']); return redirect('maintenance/owner/')->with('successTip',"成功修改货主{$owner['name']}!"); } /** * Remove the specified resource from storage. * * @param Owner $owner * @return array|Response * @throws Exception */ public function destroy(Owner $owner) { if(!Gate::allows('货主-删除')){ return redirect(url('/')); } $authority=Authority::where('name',"_{$owner['id']}")->first(); if($authority)$authority->delete(); $this->log(__METHOD__,__FUNCTION__,$owner->toJson(),Auth::user()['id']); $re=$owner->delete(); return ['success'=>$re]; } }