Created
November 1, 2017 23:41
-
-
Save dynamiccarrots/b16a4779df28a83dbde3479fa31f7a52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Advert; | |
use App\Libraries\Postcode; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\DB; | |
class AdvertController extends Controller | |
{ | |
/** | |
* @return \Illuminate\Http\JsonResponse | |
*/ | |
public function index(Request $request) | |
{ | |
$circle_radius = 100; // miles | |
$data = Advert::select('*')->where('active', '=', 1); | |
if ($request->keyword) { | |
$data->where([['title', 'like', $request->keyword . '%']]); | |
} | |
if ($request->sector) { | |
$data->where([['title', 'like', $request->keyword . '%']]); | |
} | |
if($request->location) { | |
$location = Postcode::locate($request->location); | |
$data->addSelect(" ( 3959 * acos( cos( radians('50.866431018898') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('-1.4385519869239') ) + sin( radians('50.866431018898') ) * sin( radians(latitude) ) ) ) AS distance"); | |
} | |
echo $data->toSql(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment