Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Configurator\Configuration\Http\Requests;
- use App\Models\Status;
- use Illuminate\Foundation\Http\FormRequest;
- class InvoiceRequest extends FormRequest
- {
- /**
- * Determine if the user is authorized to make this request.
- *
- * @return bool
- */
- public function authorize(): bool
- {
- return true;
- }
- /**
- * Get the validation rules that apply to the request.
- *
- * @return array
- */
- public function rules(): array
- {
- return [
- 'expired_at' => 'nullable | date | after:today',
- 'purpose' => 'required | string | max:120',
- 'sum' => 'required | numeric',
- 'title_id' => 'required | integer',
- 'is_paid' => 'boolean',
- 'configuration' => [
- static function ($attribute, $value, $fail) {
- // Status less then customer-is-ready-to-pay
- $statusId = null;
- /** @var Status $status */
- $status = Status::whereSlug('customer-is-ready-to-pay')->first();
- if ($status) {
- $statusId = $status->getKey();
- } else {
- $fail(trans('messages.invoice.status_not_found'));
- }
- if ($value->currentStatus->status_id < $statusId) {
- $fail(trans('validation.invoice.order_status'));
- }
- },
- ],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function all($keys = null): array
- {
- $request = parent::all($keys);
- $request['configuration'] = $this->route('configuration');
- return $request;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment