48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\Investment\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class ProfileInvestmentLimitRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$profileId = $this->route('investment_limit_profile');
|
|
$limitId = $this->route('limit');
|
|
|
|
$typeRule = Rule::unique('profile_investment_limits', 'investment_type_id')
|
|
->where(fn ($query) => $query->where('profile_id', $profileId));
|
|
|
|
if ($this->isMethod('PUT') || $this->isMethod('PATCH')) {
|
|
$typeRule = $typeRule->ignore($limitId);
|
|
}
|
|
|
|
return [
|
|
'investment_type_id' => [
|
|
'required',
|
|
'uuid',
|
|
'exists:investment_types,id',
|
|
$typeRule,
|
|
],
|
|
'max_investment_amount' => ['nullable', 'numeric', 'min:0'],
|
|
'max_transaction_amount' => ['nullable', 'numeric', 'min:0'],
|
|
];
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'investment_type_id.required' => 'Jenis pelaburan diperlukan.',
|
|
'investment_type_id.exists' => 'Jenis pelaburan tidak dijumpai.',
|
|
'investment_type_id.unique' => 'Had untuk jenis pelaburan ini sudah wujud dalam profil.',
|
|
];
|
|
}
|
|
}
|