/ app / Http / Requests / UpdateCertificateStatusRequest.php
UpdateCertificateStatusRequest.php
 1  <?php
 2  
 3  namespace App\Http\Requests;
 4  
 5  use App\Exceptions\EnisaValidationApiException;
 6  use Illuminate\Contracts\Validation\Validator;
 7  use Illuminate\Foundation\Http\FormRequest;
 8  
 9  class UpdateCertificateStatusRequest extends FormRequest
10  {
11      /**
12       * Determine if the user is authorized to make this request.
13       *
14       * @return bool
15       */
16      public function authorize(): bool
17      {
18          return true;
19      }
20  
21      /**
22       * Get the validation rules that apply to the request.
23       *
24       * @return array<string, mixed>
25       */
26      public function rules(): array
27      {
28          return [
29              'id' => 'required|exists:certificates,id',
30              'status' => 'required|boolean',
31              'message' => 'nullable|string',
32              'qr_code' => 'required_if:status,true|string',
33          ];
34      }
35  
36      public function messages(): array
37      {
38          return [
39              'id.required' => 'Missing parameter: id',
40              'status.required' => 'Missing parameter: status',
41              'id.exists' => 'Invalid id',
42              'qr_code.required_if' => 'Missing parameter: qr_code'
43          ];
44      }
45  
46      protected function failedValidation(Validator $validator): void
47      {
48          throw new EnisaValidationApiException($validator);
49      }
50  }