fix: makes portfolio available to form request

This commit is contained in:
hackerESQ
2025-01-27 23:08:23 -06:00
parent 465686dbaf
commit 53ebe28b14
2 changed files with 12 additions and 3 deletions
+10 -2
View File
@@ -10,6 +10,14 @@ use App\Rules\QuantityValidationRule;
class TransactionRequest extends FormRequest
{
protected function prepareForValidation(): void
{
$this->merge([
'portfolio' => Portfolio::find($this->requestOrModelValue('portfolio_id', 'transaction'))
]);
}
/**
* Get the validation rules that apply to the request.
*
@@ -17,7 +25,7 @@ class TransactionRequest extends FormRequest
*/
public function rules(): array
{
$rules = [
'portfolio_id' => ['required', 'exists:portfolios,id'],
'symbol' => ['required', 'string', new SymbolValidationRule],
@@ -28,7 +36,7 @@ class TransactionRequest extends FormRequest
'numeric',
'min:0',
new QuantityValidationRule(
$this->requestOrModelValue('symbol', 'transaction'),
$this->input('portfolio'),
$this->requestOrModelValue('symbol', 'transaction'),
$this->requestOrModelValue('transaction_type', 'transaction'),
$this->requestOrModelValue('date', 'transaction')