Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

andyandy's avatar

ST_Distance_Sphere does not exist

I want to display results that are within $distance (GPS coordinates).

<?php

namespace App\Http\Controllers;

use App\Record;

class SearchResultsController extends Controller
{
    public function search()
    {

        $lon = 0;
        $lat = 0;
        $distance=1000000;
        return Record::whereRaw('ST_Distance_Sphere(point(latitude, longitude),POINT('.$lat.','.$lon.')) < '.$distance)->get();

        
    }
}

But I'm getting ERROR:

SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION database.ST_Distance_Sphere does not exist (SQL: select * from `records` where ST_Distance_Sphere(point(latitude, longitude),POINT(0,0)) < 1000000)

I don't know what to try anymore.

0 likes
4 replies
andyandy's avatar

My XAMPP control panel says I'm using MySQL (which supports this function), but info files about my XAMPP mentions I'm using MariaDB, which doesn't support this.

Sinnbeck's avatar

Try checking from laravel what you are actually using

dd(\DB::raw('SHOW VARIABLES LIKE "%version%"'));

Please or to participate in this conversation.