46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\Products\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
final class StoreProductRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return $this->user() !== null;
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'is_active' => $this->boolean('is_active'),
|
|
'is_featured' => $this->boolean('is_featured'),
|
|
'features' => collect(preg_split('/\r\n|\r|\n/', (string) $this->input('features')))
|
|
->map(fn (string $feature) => trim($feature))
|
|
->filter()
|
|
->values()
|
|
->all(),
|
|
]);
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'product_type' => ['required', 'in:product,plan'],
|
|
'description' => ['nullable', 'string'],
|
|
'price' => ['nullable', 'numeric', 'min:0'],
|
|
'currency' => ['required', 'string', 'size:3'],
|
|
'billing_period' => ['nullable', 'string', 'max:40'],
|
|
'features' => ['array'],
|
|
'features.*' => ['string', 'max:255'],
|
|
'cta_label' => ['nullable', 'string', 'max:80'],
|
|
'cta_url' => ['nullable', 'string', 'max:2048'],
|
|
'is_featured' => ['boolean'],
|
|
'sort_order' => ['integer', 'min:0'],
|
|
'is_active' => ['boolean'],
|
|
];
|
|
}
|
|
}
|