[ 'rules' => [ 'name' => 'required', ] ], 'update' => [ 'rules' => [ 'id' => 'bail|min:1', 'name' => 'required', ], 'custom' => [ 'exists,App\Models\CarBrandT,id', ] ], ]; public function __construct(Request $request) { $this->model = new CarBrandT(); 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 CarBrandCollection($query->paginate())); } else { return $this->success($query->get()); } } /** * @title 车辆品牌保存 * @description 车辆品牌保存 * @return \Illuminate\Http\JsonResponse * @author zcstatham */ public function store() { $this->model->name = $this->params['name']; $this->model->logo = $this->params['logo']; $this->model->letter = $this->params['letter']; if($this->model->save()){ return $this->success(new CarBrand($this->model)); } else { return $this->error(500, '车辆品牌信息保存失败'); } } /** * @title 车辆品牌更新 * @description 车辆品牌更新 * @param $id * @return \Illuminate\Http\JsonResponse * @author zcstatham */ public function update($id) { $this->model = $this->model->where('id', $id)->first(); $this->model->name = $this->params['name']; $this->model->logo = $this->params['logo']; $this->model->letter = $this->params['letter']; if($this->model->save()){ return $this->success(new CarBrand($this->model)); } else { return $this->error(500, '车辆品牌信息保存失败'); } } }