<?php

$path="../../";
require($path .'core/includes/header.inc.php');

$term = filter_input(INPUT_GET, 'term');

if (!empty($term)) {

    $doctor_surgeries = \Mtc\Modules\DoctorSurgery\Classes\DoctorSurgery::query()
        ->where('practice_name', 'like', "%{$term}%")
        ->orWhere('address_1', 'like', "%{$term}%")
        ->orWhere('address_2', 'like', "%{$term}%")
        ->orWhere('address_3', 'like', "%{$term}%")
        ->orWhere('city', 'like', "%{$term}%")
        ->orWhere('postcode', 'like', "%{$term}%")
        ->take(10)
        ->get();

    $response = [
        'status' => 'ok',
        'doctor_surgeries' => $doctor_surgeries,
    ];

    header('Content-Type: application/json');
    echo json_encode($response);
    exit;
}