首页 > 解决方案 > How to Convert received data from Database to string in laravel?

问题描述

So before everything this is not duplicate.

I've got a callback method which will get 2 parameters from payment getway. the function they gave us need Amount to make sure everything is correct and base on Amount they gonna gave us payment status, but they won't post it, i should get it from my Database which i've did base on this code :

public function order(Request $request){
    $MerchantID = 'xxxxxxxxxxx';
    $Authority =$request->get('Authority') ;

    $Amount = Invoice::select('invoice_balance')->where('authority',$Authority)->get();
    if ($request->get('Status') == 'OK') {
        $client = new nusoap_client('https://www.localhost.com/pg/services/WebGate/wsdl', 'wsdl');
        $client->soap_defencoding = 'UTF-8';
        $result = $client->call('PaymentVerification', [
            [
                'MerchantID'     => $MerchantID,
                'Authority'      => $Authority,
                'Amount'         => $Amount,
            ],
        ]);

        if ($result['Status'] == 100) {
            return 'Done.';

        } else {
            return 'Error with 1';
        }
    }
    else
    {
        return 'Error with 2';
    }
//        return $Amount;

}

when i use this code i get The Response content must be a string or object implementing __toString(), "boolean" given. which i'm pretty sure it's just about Amount part, because when use manual value for Amount (exact amount of cart in $Amount = amount), it's gonna gave me The Response content must be a string or object implementing __toString(), "boolean" given. Error.

I've also tried someways in other questions but didn't worked. if u remove whole if(status... part and only return $Amount to make sure it work it gonna gave [{"invoice_balance":"2000"}] which i don't know if this is my mistake or not. please help me, i'm in learning process.

Invoice Model(if needed):

class Invoice extends Model   {
protected $fillable = [
    'from_user_id', 'to_user_id', 'invoice_title', 'invoice_description', 'invoice_balance', 'invoice_due_date', 'status'
];

protected $hidden = [
    'authority'
];
public function user()
{
    return $this->belongsTo(User::class);
}
}

标签: laravel

解决方案


那么解决方案正在改变

$Amount = Invoice::select('invoice_balance')->where('authority',$Authority)->get();

$Amount = Invoice::select('invoice_balance')->where('authority',$Authority)->value('authority');


推荐阅读