Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 35 |
| OwnerController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
272.00 | |
0.00% |
0 / 35 |
| index | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 3 |
|||
| create | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 2 |
|||
| store | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| validatorCreate | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| validatorUpdate | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| show | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
| edit | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 2 |
|||
| update | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 6 |
|||
| destroy | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 6 |
|||
| <?php | |
| namespace App\Http\Controllers; | |
| use App\Authority; | |
| use App\Log; | |
| use App\Logistic; | |
| use App\Owner; | |
| use Exception; | |
| use Illuminate\Http\Request; | |
| use Illuminate\Http\Response; | |
| use Illuminate\Support\Facades\Auth; | |
| use Illuminate\Support\Facades\Gate; | |
| use Illuminate\Support\Facades\Validator; | |
| class OwnerController extends Controller | |
| { | |
| /** | |
| * Display a listing of the resource. | |
| * | |
| * @return Response | |
| */ | |
| public function index() | |
| { | |
| if(!Gate::allows('货主-查询')){ return redirect(url('/')); } | |
| $owners=Owner::orderBy('id','desc')->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]; | |
| } | |
| } |