Laravel自定义规则将值与数据库进行比较

时间:2018-06-20 17:25:50

标签: laravel

我试图从输入文本中获取一个值,并比较输入的值(“取款”),并确保从数据库中获得的钱包余额少,并且如果MORE或EQUAL返回错误。这是我的代码:

  public function store(Request $request)
    {   
        $this->CurrentUserProfile = User::find(GeneralHelper::GetAuthUserId());  
        $CustomerInfo = Customer_M::Where('User_ID','=',$this->CurrentUserProfile->User_ID)->Get();
        $CustomerWallets = CustomerWallet_M::Where('Cus_ID','=',$CustomerInfo[0]->Cus_ID)->Get();
        $WalletBalanceFromDatabase = $CustomerWallets[0]->CusWalletBalance;

        $validator = Validator::make($request->all(), [
            'WithdrawalAmount' => [
                function($attribute, $value, $fail) use ($WalletBalanceFromDatabase)  {
                    if ($PTransferAmount > $WalletBalanceFromDatabase) {
                        return $fail('You wallet funds is insufficient');
                    }
                },
            ],
        ]);

    }

我的问题是我完全遵循https://laravel.com/docs/5.6/validation#using-closures ...,但仍然出现错误:类Closure的对象无法转换为字符串

0 个答案:

没有答案