app/Http/Requests/Operation/UpdateRequest.php
/**
     * Configure the validator instance.
     *
     * @param  \Illuminate\Validation\Validator  $validator
     * @return void
     */
Configure the validator instance.
@param  \Illuminate\Validation\Validator  $validator
@return void
Configure the validator instance . @param \ Illuminate \ Validation \ Validator $validator @return void
public function withValidator($validator)
    {
        $validator->after(function ($validator) {
            $data = $validator->validated();
            $operation = $this->route('operation');
            $account = Account::find($data['account_id']);
            if (!isset($data['is_income']) && (($account->balance + $operation->amount) < floatval($data['amount']))) {
                $validator->errors()->add('amount', $account->balance . ' on balance');
            }
        });
    }
public function withValidator ( $ validator ) { $ validator -> after ( function ( $ validator ) { $ data = $ validator -> validated ( ) ; $ operation = $ this -> route ( 'operation' ) ; $ account = Account :: find ( $ data [ 'account_id' ] ) ; if ( ! isset ( $ data [ 'is_income' ] ) && ( ( $ account -> balance + $ operation -> amount ) < floatval ( $ data [ 'amount' ] ) ) ) { $ validator -> errors ( ) -> add ( 'amount' , $ account -> balance . ' on balance' ) ; } } ) ; }
Configure the validator instance.
Configure the validator instance .