[ 'rules' => [ 'car_brand_id' => 'required', 'name' => 'required', ] ], 'update' => [ 'rules' => [ 'id' => 'bail|min:1', 'car_brand_id' => 'required', 'name' => 'required', ], 'custom' => [ 'exists,App\Models\CarSubBrandT,id', ] ], ]; public function __construct(Request $request) { $this->model = new CarSubBrandT(); parent::__construct($request); } /** * @title 厂家列表 * @description 厂家列表 * @return \Illuminate\Http\JsonResponse * @author zcstatham */ public function index() { $query = $this->model->query(); if(isset($this->params['name']) && $this->params['name'] != ''){ $query->where('name', $this->params['name']); } if(isset($this->params['car_brand_id']) && $this->params['car_brand_id'] > 0){ $query->where('car_brand_id', $this->params['car_brand_id']); } if(isset($this->params['is_page']) && $this->params['is_page'] == 1){ return $this->success(new CarSubBrandCollection($query->paginate())); } else { return $this->success($query->get()); } } /** * @title 厂家保存 * @description 厂家保存 * @return \Illuminate\Http\JsonResponse * @author zcstatham */ public function store() { $this->model->car_brand_id = $this->params['car_brand_id']; $this->model->name = $this->params['name']; if($this->model->save()){ return $this->success(new CarSubBrand($this->model)); } else { return $this->error(500, '厂家信息保存失败'); } } /** * @title 厂家详情 * @description 厂家详情 * @param $id * @return mixed * @author zcstatham */ public function show($id) { return $this->success(new CarSubBrand($this->model->where('id', $id)->first())); } /** * @title 厂家更新 * @description 厂家更新 * @param $id * @return \Illuminate\Http\JsonResponse * @author zcstatham */ public function update($id) { $this->model = $this->model->where('id', $id)->first(); $this->model->car_brand_id = $this->params['car_brand_id']; $this->model->name = $this->params['name']; if($this->model->save()){ return $this->success(new CarSubBrand($this->model)); } else { return $this->error(500, '厂家信息保存失败'); } } /** * @title 厂家删除 * @description 厂家删除 * @param $id * @return \Illuminate\Http\JsonResponse * @author zcstatham */ public function destroy($id) { if($this->model->destroy($id)){ return $this->success(); } else { return $this->error(500, '厂家信息保存失败'); } } }