/
itp_practice
/
itp_backend
Обзор
Документация
Войти
/
itp_practice
/
itp_backend
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
app/Http/Requests/Admin/CreateOrderRequest.php
54 строки
2 KB
vivanenko
add purchase create from admin
29 май 2025, 11:13
29 май 2025, 11:13
25c496a
Код
Авторство
О чём код?
<?php namespace App\Http\Requests\Admin; use Illuminate\Foundation\Http\FormRequest; class CreateOrderRequest extends FormRequest { /** * Determine if the user is authorized to make this request. */ public function authorize(): bool { // Проверяем, что пользователь имеет роль админа return $this->user() && $this->user()->hasRole('admin'); } /** * Get the validation rules that apply to the request. */ public function rules(): array { return [ 'user_id' => 'required|integer|exists:users,id', 'tariff_id' => 'required|integer|exists:tariffs,id', 'quantity' => 'required|integer|min:1', 'discount_amount' => 'nullable|numeric|min:0', 'payment_gateway' => 'nullable|string|in:freekassa,freekassa_mock,demo', 'currency' => 'nullable|string|in:RUB,USD,EUR', 'coupon_code' => 'nullable|string|max:50', 'metadata' => 'nullable|array', 'metadata.admin_note' => 'nullable|string|max:500', 'metadata.created_by' => 'nullable|string|max:100', ]; } /** * Get custom error messages. */ public function messages(): array { return [ 'user_id.required' => 'Необходимо выбрать пользователя', 'user_id.exists' => 'Выбранный пользователь не существует', 'tariff_id.required' => 'Необходимо выбрать тариф', 'tariff_id.exists' => 'Выбранный тариф не существует', 'quantity.required' => 'Необходимо указать количество', 'quantity.min' => 'Количество должно быть больше 0', 'discount_amount.min' => 'Сумма скидки не может быть отрицательной', 'payment_gateway.in' => 'Неподдерживаемый платежный шлюз', 'currency.in' => 'Неподдерживаемая валюта', ]; } }