Skip to content
Advertisement

How to return an array using Laravel Eloquent select?

I have this class

JavaScript

when I call radiusSearch(...) I get a IlluminateDatabaseEloquentBuilder object and not the actual result

$result->get() doesn’t work, I get Object of class IlluminateDatabaseEloquentBuilder could not be converted to string

This generic query works just fine ZipCode::where('zip', '11111')->get() just not the above one

Any ideas?

EDIT: the $result returns something like this:

JavaScript

If I do $result->getModel()->get()->toArray() this returns all results from the table

Advertisement

Answer

Here is the solution I came up with based on some other community answers

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement