MJ DEV
MJ DEV

Reputation: 704

want to get difference between two values

i want to get difference between two values. i get my last entered value in bill no and get difference with input value.

this is my controller function model

$restPaymentSales = DB::table('sales')
                    ->select('rest_payment')
                    ->where('bill_no', $request->input('bill_no')) 
                    ->orderBy('created_at', 'desc')
                    ->first(); 

$payment = $request->input('payment');    

$doubleVal = doubleval($payment); 

and i wrote calculation like this

$restSales = $restPaymentSales->child['rest_payment'] - $doubleVal;

but it shows me this error

Trying to get property of non-object

my table row like this

rest_payment -> double(11,2)

how can i fix this issue. basically i want to get difference between table last value order by date and input value.

Upvotes: 0

Views: 1167

Answers (1)

Vidal
Vidal

Reputation: 2621

Update your calculation from:

$restSales = $restPaymentSales->child['rest_payment'] - $doubleVal;

TO

$restSales = $restPaymentSales->rest_payment - $doubleVal;

Upvotes: 2

Related Questions