57 lines
1.8 KiB
PHP
Executable File
57 lines
1.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Requests\Admin\Manage;
|
|
|
|
use App\Traits\NotificationTrait;
|
|
use Illuminate\Contracts\Validation\Validator;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class TransactionRequest extends FormRequest
|
|
{
|
|
use NotificationTrait;
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return Auth::check();
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'price' => removeRupiahFormatting($this->price),
|
|
'discount' => removeRupiahFormatting($this->discount),
|
|
'total' => removeRupiahFormatting($this->total),
|
|
]);
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
if (! $this->route()->named('manage.transaction.print')) {
|
|
$rules = [
|
|
'barber' => ['required', Rule::exists('users', 'id')],
|
|
'service' => ['required', Rule::exists('services', 'id')],
|
|
'customer' => ['required'],
|
|
'price' => ['required', 'numeric', 'min:0', 'max:999999.99'],
|
|
'discount' => ['required', 'numeric', 'min:0', 'max:999999.99'],
|
|
'total' => ['required', 'numeric', 'min:0', 'max:999999.99'],
|
|
'image' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,svg', 'max:2048'],
|
|
'payment_method' => ['required', Rule::in(['1', '2', '3'])],
|
|
];
|
|
}
|
|
|
|
if ($this->isMethod('post') || $this->route()->named('manage.transaction.print')) {
|
|
$rules['showing_barber_name'] = ['required', Rule::in(['1', '2'])];
|
|
$rules['showing_cashier_name'] = ['required', Rule::in(['1', '2'])];
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
|
|
protected function failedValidation(Validator $validator): void
|
|
{
|
|
$this->handleValidationFailure($validator);
|
|
}
|
|
}
|