Support the ongoing development of Laravel.io →
Database Eloquent Architecture
Last updated 1 year ago.
0

If anyone want to know how to add a function to sqlite database without having to hack to source code. If you are using PDO then its real easy and even easier when the functions you want to add are part of the programming language used with PDO .

So add this to your project I used the AppServiceProvider register method.

		$pdo = DB::connection('sqlite')->getPdo();
		$pdo->sqliteCreateFunction('cos', 'cos', 1);
		$pdo->sqliteCreateFunction('acos', 'acos', 1);
		$pdo->sqliteCreateFunction('sin', 'sin', 1);
		$pdo->sqliteCreateFunction('radians', 'deg2rad', 1);
0
Solution

Fixed it I was missing a BD::raw within the having as i was using a bind param

 DB::raw("*,  ( 6371 * acos( cos( radians(?) ) * cos( radians( `latitude` ) ) * cos( radians( `longitude` ) - radians(?) ) + sin( radians(?) ) * sin( radians( `latitude` ) ) )) AS distance"))
            ->groupBy('id')
            ->having("distance", "<", DB::raw('?'))
            ->orderBy("distance")
            ->setBindings([$latitude, $longitude, $latitude, $radius])
            ->get();

0

Sign in to participate in this thread!

Eventy

Your banner here too?

apps4u apps4u Joined 7 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.