UpdateLinkAssetsRequest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Requests\API\Project;
  3. use App\Models\Asset;
  4. use App\Models\Enums\AssetStatus;
  5. use App\Models\Plan;
  6. use App\Models\User;
  7. use Illuminate\Foundation\Http\FormRequest;
  8. use Illuminate\Support\Facades\Auth;
  9. use Illuminate\Validation\Rule;
  10. use Illuminate\Validation\Rules\Enum;
  11. class UpdateLinkAssetsRequest extends FormRequest
  12. {
  13. /**
  14. * Determine if the user is authorized to make this request.
  15. */
  16. public function authorize(): bool
  17. {
  18. return true;
  19. }
  20. /**
  21. * Get the validation rules that apply to the request.
  22. *
  23. * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
  24. */
  25. public function rules(): array
  26. {
  27. return [
  28. 'project_id' =>[
  29. 'email'
  30. ],
  31. 'assets' => [
  32. 'array',
  33. function ($attribute, $value, $fail) {
  34. $assetIds = Asset::query()->whereIn('id', $value)->pluck('id')->toArray();
  35. if (count(array_diff($value, $assetIds)) > 0) {
  36. $fail('The selected asset is invalid.');
  37. }
  38. }
  39. ],
  40. ];
  41. }
  42. }