portfolio = $portfolio; $this->symbol = $symbol; $this->transactionType = $transactionType; } /** * Validate the attribute. * * @param string $attribute * @param mixed $value * @param \Closure $fail * @return void */ public function validate(string $attribute, mixed $value, \Closure $fail): void { if ($this->transactionType == 'SELL') { $holding = $this->portfolio->holdings()->symbol($this->symbol)->first(); $maxQuantity = $holding ? $holding->quantity : 0; if ($value > $maxQuantity) { $fail(__('The quantity must not be greater than the available quantity.')); } } } }