This commit is contained in:
Tokumeikoi 2020-02-23 02:37:52 +08:00
parent 018e4aa810
commit 5ee6fc2996
2 changed files with 22 additions and 21 deletions

View File

@ -21,25 +21,24 @@ class PlanController extends Controller
public function save(PlanSave $request) public function save(PlanSave $request)
{ {
$params = $request->only(array_keys(PlanSave::RULES));
if ($request->input('id')) { if ($request->input('id')) {
$plan = Plan::find($request->input('id')); $plan = Plan::find($request->input('id'));
if (!$plan) { if (!$plan) {
abort(500, '该订阅不存在'); abort(500, '该订阅不存在');
} }
} else { if (!$plan->update($params)) {
$plan = new Plan(); abort(500, '保存失败');
} }
$plan->name = $request->input('name');
$plan->content = $request->input('content');
$plan->transfer_enable = $request->input('transfer_enable');
$plan->group_id = $request->input('group_id');
$plan->month_price = $request->input('month_price');
$plan->quarter_price = $request->input('quarter_price');
$plan->half_year_price = $request->input('half_year_price');
$plan->year_price = $request->input('year_price');
return response([ return response([
'data' => $plan->save() 'data' => true
]);
}
if (!Plan::create($params)) {
abort(500, '创建失败');
}
return response([
'data' => true
]); ]);
} }

View File

@ -6,15 +6,9 @@ use Illuminate\Foundation\Http\FormRequest;
class PlanSave extends FormRequest class PlanSave extends FormRequest
{ {
/** CONST RULES = [
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required', 'name' => 'required',
'content' => '',
'group_id' => 'required', 'group_id' => 'required',
'transfer_enable' => 'required', 'transfer_enable' => 'required',
'month_price' => 'nullable|integer', 'month_price' => 'nullable|integer',
@ -22,6 +16,14 @@ class PlanSave extends FormRequest
'half_year_price' => 'nullable|integer', 'half_year_price' => 'nullable|integer',
'year_price' => 'nullable|integer' 'year_price' => 'nullable|integer'
]; ];
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return self::RULES;
} }
public function messages() public function messages()