CreateOrUpdateRequest.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Http\Requests\API\Plan;
  3. use App\Http\Requests\RuleHelper;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Validation\Rule;
  6. class CreateOrUpdateRequest extends FormRequest
  7. {
  8. use RuleHelper;
  9. /**
  10. * Determine if the user is authorized to make this request.
  11. */
  12. public function authorize(): bool
  13. {
  14. return true;
  15. }
  16. /**
  17. * Get the validation rules that apply to the request.
  18. *
  19. * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
  20. */
  21. public function rules(): array
  22. {
  23. return [
  24. 'asset_id' => [
  25. 'required',
  26. Rule::exists('assets', 'id')->where($this->userCompanyWhere()),
  27. ],
  28. 'title' => 'required|max:255',
  29. 'begin' => 'date',
  30. 'end' => 'date',
  31. 'parent_id' => [
  32. Rule::exists('plans', 'id')->where($this->userCompanyWhere())->where("asset_id", $this->post("asset_id")),
  33. ]
  34. ];
  35. }
  36. }