Q:

Laravel 4.1 Raw Query accessing result

I'm using the Haversine formula to create a nearby function in laravel 4.1, my raw query:
    $haversine = '(3959 * acos(cos(radians(' . $lat . ')) * cos(radians(lat)) * cos(radians(lng) - radians(' . $lng . ')) + sin(radians(' . $lat . ')) * sin(radians(lat))))';

    $places = DB::table('b_details')
        ->select(DB::raw($haversine . ' as distance'))
        ->orderBy('distance', 'ASC')
        ->having('distance', '<', $radius)
        ->get();

    foreach ($places as $place) {
        var_dump($place);
    }

this only returns the result of the calculation like so: 
object(stdClass)[231]
  public 'distance' => float 0.037140269070672
object(stdClass)[232]
  public 'distance' => float 0.093237928677323
object(stdClass)[233]
  public 'distance' => float 0.4404396657947

I'm unable to access anymore data, for example: 
    foreach ($places as $place) {
        var_dump($place->name);
    }

produces this error: 
 Undefined property: stdClass::$name

Any help is appreciated, thank you.  

A:

Your select list should be an array of columns to select (though it will convert a single string to a single element array): you're only listing one item to return, the distance, so it will only return that one item.... you need to tell it to return all other data columns as well
$places = DB::table('b_details')
    ->select( array('*', DB::raw($haversine . ' as distance')) )
    ->orderBy('distance', 'ASC')
    ->having('distance', '<', $radius)
    ->get();

