Takes first SQL Bullider Laravel record

Asked

Viewed 116 times

1

I’m not getting the first record without using foreach

query = "SELECT *, (SELECT count(*) FROM corridas c WHERE c.motoqueiro = u.id AND (c.status = 0 OR c.status = 1)) as corrida ,distance_between(u.latitude, u.longitude, $lat, $lon) as km FROM (SELECT * FROM motoqueiros WHERE DATE_SUB(NOW(),INTERVAL 8 SECOND) <= data_update) order by km ASC LIMIT 1";

    $data = DB::select($query);

$date[0], error > Undefined offset: 0

toArray, error > Fatal error: Call to a Member Function toArray() on array

.get , error > Fatal error: Call to a Member Function get() on array

I’ve tried using $data[0], toArray, . get, first and nothing, someone help me and, vlw!

  • The error is not in this part of the code. I copied all the code. Alias, read the error carefully "Fatal error: Call to a Member Function toArray() on array"

  • Probably your query is wrong and $data is getting a false one. Try making a var_dump($data) and confirm the structure.

No answers

Browser other questions tagged

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