You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
user_center/app/Http/Controllers/Api/CarBrandController.php

104 lines
2.8 KiB

<?php
namespace App\Http\Controllers\Api;
use App\Http\Resources\CarBrand;
use App\Http\Resources\CarBrandCollection;
use App\Models\CarBrandT;
use Illuminate\Http\Request;
/**
* @title 车辆品牌管理
* @description CarBrandController
* @package App\Http\Controllers\Api
* @author zcstatham
*/
class CarBrandController extends BaseController
{
protected $rules = [
'store' => [
'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, '车辆品牌信息保存失败');
}
}
}