50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\Setting;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class SettingUpdateRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* آمادهسازی دادهها بر اساس ردیفهای موجود در جدول.
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$allowedCodes = Setting::pluck('code')->all();
|
|
|
|
// فقط codeهایی که در جدول وجود دارند را نگاه میداریم
|
|
$filtered = Arr::only($this->all(), $allowedCodes);
|
|
|
|
$this->merge($filtered);
|
|
}
|
|
|
|
/**
|
|
* قوانین اعتبارسنجی.
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$codes = Setting::pluck('code')->all();
|
|
|
|
return collect($codes)
|
|
->mapWithKeys(fn($code) => [
|
|
$code => [
|
|
'nullable',
|
|
'string',
|
|
'max:65535'
|
|
],
|
|
])
|
|
->all();
|
|
}
|
|
}
|