59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class MerchantController extends Controller
|
|
{
|
|
/**
|
|
* GET /api/merchants
|
|
* Get all customers (aliased as merchants for frontend compatibility)
|
|
*/
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
// Switch to Customer model
|
|
$query = \App\Models\Customer::query();
|
|
|
|
// Filter by bbox
|
|
if ($request->has('bbox') && !empty($request->bbox)) {
|
|
$bbox = explode(',', $request->bbox);
|
|
if (count($bbox) === 4) {
|
|
$minLng = (float) $bbox[0];
|
|
$minLat = (float) $bbox[1];
|
|
$maxLng = (float) $bbox[2];
|
|
$maxLat = (float) $bbox[3];
|
|
|
|
$query->where('latitude', '>=', $minLat)
|
|
->where('latitude', '<=', $maxLat)
|
|
->where('longitude', '>=', $minLng)
|
|
->where('longitude', '<=', $maxLng);
|
|
}
|
|
}
|
|
|
|
// Filter by categories
|
|
if ($request->has('categories') && !empty($request->categories)) {
|
|
$categories = explode(',', $request->categories);
|
|
$query->whereIn('category', $categories);
|
|
}
|
|
|
|
$customers = $query->get();
|
|
|
|
// return formatted data
|
|
$data = $customers->map(function ($m) {
|
|
return [
|
|
'id' => $m->id,
|
|
'name' => $m->name,
|
|
'category' => $m->category ?? 'other',
|
|
'latitude' => (float) $m->latitude,
|
|
'longitude' => (float) $m->longitude,
|
|
'city' => $m->city ?? '',
|
|
'address' => $m->address ?? ''
|
|
];
|
|
});
|
|
|
|
return response()->json($data);
|
|
}
|
|
}
|