Eloquent returning field and value

Asked

Viewed 20 times

-1

My select is returning the field and value of the id that is in the table and need to return only the value,?

$id = DB::table('participantes')
        ->select('id')
        ->orderBy('id','DESC')
        ->take(1)
        ->get();

Error returned

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '[{"id":173}]' for column 'participante_id' at Row 1 (SQL: Insert into participantes (opcao_id, questao_id, participante_id) values (291, 84, [{"id":173}]))

  • Do you know that get is different from first right?

1 answer

0


Have you ever tried to just take the id of the result instead of using the array?

$result = DB::table('participantes')
        ->select('id')
        ->orderBy('id','DESC')
        ->first();

$id = $result->id;
  • Fernando, is returning Cannot use Object of type stdClass as array. with the code as you sent me.

  • Fault mine, edited...

  • It worked, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.