mardi 22 novembre 2016

Trying to get property of non-object laravel 5.1 on DB::first()

I'm using Laravel 5.1 on a project, and I'm getting "Trying to get property of non-object" error on this code:

$eval = DB::table('control_eval_risk_temp')
                        ->where('control_id','=',$control->id)
                        ->where('created_at','=',$max_date)
                        ->select('result')
                        ->first();
if ($eval->result  == 1)
{
     $cont += 1;
}

I have this error specifically on the "if sentence", but if I try this:

echo getType($eval);

That returns "object", and if I try:

echo $eval->result;

This returns 1 (so it have a value), and after return the message "Trying to get property of non-object", so I don't understand where is the mistake since the var $eval is an object and $eval->result have a value.

Thank's in advance!.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire