Skip to content
Advertisement

Cannot convert to integer from illuminate

I retrieve data:

$credit = DB::table('expert')
    ->where('use_id', $use_id)
    ->select('credit')
    ->get();

if ($count < $credit) {
    return response()->json(true);
}

However, it failed at the $count < $credit, error Object of class IlluminateSupportCollection could not be converted to int, I tried putting ->first(); got same thing

Advertisement

Answer

->get() will return the collection.

->first() instead of ->get() return the query builder stdClass of expert table.

So you need to call its attribute like this:

$credit = DB::table('expert')
    ->where('use_id', $use_id)
    ->select('credit')
    ->first()->credit;
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement