<?php namespace App\Http\Requests\System; use App\Http\Requests\Request; use Illuminate\Validation\Rule; class PermissionSaveRequest extends Request { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return true; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { if (!$this->ajax()) { return []; } $addition = []; if ($this->route('id') == 0) { //添加时验证 $addition['parent_id'] = 'required|numeric'; } return [ 'title' => 'required', 'rule' => 'nullable', 'icon' => 'nullable', 'type' => ['required', Rule::in([1, 2])], 'sort' => 'required|numeric', ] + $addition; } public function attributes() { return [ 'title' => '权限名称', 'type' => '权限类型', 'rule' => '权限标识', 'icon' => '图标', 'parent_id' => '父ID', 'sort' => '排序', ]; } }