ConfigCategoryRequest.php 906 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Http\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. use Illuminate\Support\Arr;
  5. class ConfigCategoryRequest extends FormRequest
  6. {
  7. /**
  8. * Get the validation rules that apply to the request.
  9. *
  10. * @return array
  11. */
  12. public function rules()
  13. {
  14. $cateId = (int) $this->route()->originalParameter('config_category');
  15. $rule = function ($field) use ($cateId) {
  16. return "required|string|max:50|unique:config_categories,{$field},".(int) $cateId;
  17. };
  18. $rules = [
  19. 'name' => $rule('name'),
  20. 'slug' => $rule('slug'),
  21. ];
  22. if ($this->isMethod('put')) {
  23. $rules = Arr::only($rules, $this->keys());
  24. }
  25. return $rules;
  26. }
  27. public function attributes()
  28. {
  29. return [
  30. 'name' => '名称',
  31. 'slug' => '标识',
  32. ];
  33. }
  34. }