Change headers for GET calls

This commit is contained in:
2025-09-06 09:32:24 +10:00
parent 0868b04298
commit 91792252a7

View File

@ -102,7 +102,33 @@ class DeviceApiController extends Controller
Command::whereIn('id', $cmds->pluck('id'))->update(['status' => 'sent', 'updated_at' => now()]); Command::whereIn('id', $cmds->pluck('id'))->update(['status' => 'sent', 'updated_at' => now()]);
} }
return response()->json(['commands' => $cmds]); $payload = $cmds->map(function ($c) {
return [
'id' => $c->id,
'type' => $c->command_type, // rename field to "type"
'payload' => $c->payload ?? new \stdClass(),
'priority' => $c->priority,
'created_at' => $c->created_at,
];
});
// Mark as sent (optional your current behavior)
if ($cmds->count()) {
\App\Models\Command::whereIn('id', $cmds->pluck('id'))
->update(['status' => 'sent', 'updated_at' => now()]);
}
$bodyArray = $payload->values()->all(); // a plain array
$body = json_encode($bodyArray, JSON_UNESCAPED_SLASHES);
$len = strlen($body);
return response($body, 200)
->header('Content-Type', 'application/json')
->header('Content-Length', (string)$len)
->header('Connection', 'keep-alive');
// return response()->json(['commands' => $cmds]);
} }
// POST /api/device/{imei}/command-receipts // POST /api/device/{imei}/command-receipts