2016-03-19 20 views
0

ile Sorgu ben user_location için özel bir veri türü (POINT) sahip, bir tablo bu-laravel Sorgu Oluşturucu - Özel Veri Tipi

Yani

enter image description here

gibi var.

RAW seçme sorgusu bu-

SELECT 
    id, 
    full_name, 
    website, 
    X(user_location) AS "latitude", 
    Y(user_location) AS "longitude", 
    (
    GLength(
     LineStringFromWKB(
     LineString(
      user_location, 
      GeomFromText('POINT(51.5177 -0.0968)') 
     ) 
    ) 
    ) 
) 
    AS distance 
FROM users 
    ORDER BY distance ASC; 

gibidir Ve sonucudur -

enter link description here

Ben Sorgu oluşturucu ile laravel kullanmak istediğiniz (51.5177-0.0968) bu yüzden Kullanıcı girişinden 2 puan gelebilir.

Ben

DB::table('users') 
    ->select(
      id, 
      full_name, 
      website, 
      DB::raw('X(user_location) AS "latitude"'), 
      DB::raw('Y(user_location) AS "longitude"'), 
      DB::raw('(
         GLength(
          LineStringFromWKB(
          LineString(
           user_location, 
           GeomFromText('POINT(51.5177 -0.0968)') 
          ) 
         ) 
         ) 
        ) 
         AS distance') 
      ) 
    ->orderBy('distance', 'asc') 
    ->get(); 

IS- yapmış Ama çalışmıyor ne.

Lütfen yardım edebilir misiniz?

cevap

1

Bence oldukça yakınsınız. Bunu deneyin:

DB::table('users') 
    ->select(
     'id', 
     'full_name', 
     'website', 
     DB::raw('X(user_location) as latitude'), 
     DB::raw('Y(user_location) as longitude'), 
     DB::raw('(
       GLength(
        LineStringFromWKB(
        LineString(
         user_location, 
         GeomFromText(POINT(51.5177 - 0.0968)) 
        ) 
       ) 
       ) 
      ) 
       as distance') 
    ) 
    ->where('status', '<>', 1) 
    ->orderBy('distance', 'asc') 
    ->get(); 
+0

Merhaba, biraz güncelleme, lütfen bir göz atabilir misiniz? –