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
<?php
namespace App\Http\Controllers;
use App\QualityLabel;
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 QualityLabelController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        if(!Gate::allows('品质标签-查询')){ return redirect(url('/'));  }
        $qualityLabels=QualityLabel::orderBy('id','desc')->paginate(35);
        return view('maintenance.qualityLabel.index',['qualityLabels'=>$qualityLabels]);
    }
    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
        if(!Gate::allows('品质标签-录入')){ return redirect(url('/'));  }
        return view('maintenance.qualityLabel.create');
    }
    /**
     * Store a newly created resource in storage.
     *
     * @param Request $request
     * @return Response
     */
    public function store(Request $request)
    {
        if(!Gate::allows('品质标签-录入')){ return redirect(url('/'));  }
        $this->validatorCreate($request->all())->validate();
        $qualityLabel=new QualityLabel($request->all());
        $qualityLabel->save();
        $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
        return redirect('maintenance/qualityLabel/create')->with('successTip',"成功录入品质标签“{$request->input('name')}");
    }
    protected function validatorCreate(array $data)
    {
        return Validator::make($data, [
            'name' => ['required', 'string', 'max:50', 'unique:quality_labels'],
        ]);
    }
    protected function validatorUpdate(array $data)
    {
        return Validator::make($data, [
            'name' => ['required', 'string', 'max:50'],
        ]);
    }
    /**
     * Display the specified resource.
     *
     * @param QualityLabel $qualityLabel
     * @return void
     */
    public function show(QualityLabel $qualityLabel)
    {
        //
    }
    /**
     * Show the form for editing the specified resource.
     *
     * @param QualityLabel $qualityLabel
     * @return Response
     */
    public function edit(QualityLabel $qualityLabel)
    {
        if(!Gate::allows('品质标签-编辑')){ return redirect(url('/'));  }
        return view('maintenance.qualityLabel.edit',['qualityLabel'=>$qualityLabel]);
    }
    /**
     * Update the specified resource in storage.
     *
     * @param Request $request
     * @param QualityLabel $qualityLabel
     * @return Response
     */
    public function update(Request $request, QualityLabel $qualityLabel)
    {
        if(!Gate::allows('品质标签-编辑')){ return redirect(url('/'));  }
        $this->validatorUpdate($request->all())->validate();
        $qualityLabel->fill($request->all());
        $qualityLabel->update();
        $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
        return redirect('maintenance/qualityLabel/')->with('successTip',"成功修改品质标签“{$qualityLabel['name']}”!");
    }
    /**
     * Remove the specified resource from storage.
     *
     * @param QualityLabel $qualityLabel
     * @return array|Response
     * @throws Exception
     */
    public function destroy(QualityLabel $qualityLabel)
    {
        if(!Gate::allows('品质标签-删除')){ return redirect(url('/'));  }
        $this->log(__METHOD__,__FUNCTION__,$qualityLabel->toJson(),Auth::user()['id']);
        $re=$qualityLabel->delete();
        return ['success'=>$re];
    }
}