TeeZ0NE

StatusRequest

Jun 13th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.77 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Configurator\Configuration\Http\Requests;
  4.  
  5. use App\Models\Status;
  6. use Illuminate\Foundation\Http\FormRequest;
  7.  
  8. class InvoiceRequest extends FormRequest
  9. {
  10.     /**
  11.      * Determine if the user is authorized to make this request.
  12.      *
  13.      * @return bool
  14.      */
  15.     public function authorize(): bool
  16.     {
  17.         return true;
  18.     }
  19.  
  20.     /**
  21.      * Get the validation rules that apply to the request.
  22.      *
  23.      * @return array
  24.      */
  25.     public function rules(): array
  26.     {
  27.         return [
  28.             'expired_at' => 'nullable | date | after:today',
  29.             'purpose' => 'required | string | max:120',
  30.             'sum' => 'required | numeric',
  31.             'title_id' => 'required | integer',
  32.             'is_paid' => 'boolean',
  33.             'configuration' => [
  34.                 static function ($attribute, $value, $fail) {
  35.                     // Status less then customer-is-ready-to-pay
  36.                     $statusId = null;
  37.                     /** @var Status $status */
  38.                     $status = Status::whereSlug('customer-is-ready-to-pay')->first();
  39.                     if ($status) {
  40.                         $statusId = $status->getKey();
  41.                     } else {
  42.                         $fail(trans('messages.invoice.status_not_found'));
  43.                     }
  44.  
  45.                     if ($value->currentStatus->status_id < $statusId) {
  46.                         $fail(trans('validation.invoice.order_status'));
  47.                     }
  48.                 },
  49.             ],
  50.         ];
  51.     }
  52.  
  53.     /**
  54.      * {@inheritdoc}
  55.      */
  56.     public function all($keys = null): array
  57.     {
  58.         $request = parent::all($keys);
  59.         $request['configuration'] = $this->route('configuration');
  60.  
  61.         return $request;
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment