lasthourcloud/bootstrap/helpers/api.php

39 lines
920 B
PHP
Raw Normal View History

<?php
2024-06-21 14:46:13 +00:00
use Illuminate\Database\Eloquent\Collection;
function get_team_id_from_token()
{
$token = auth()->user()->currentAccessToken();
2024-06-10 20:43:34 +00:00
return data_get($token, 'team_id');
}
2024-03-07 11:27:23 +00:00
function invalid_token()
{
2024-03-27 10:07:29 +00:00
return response()->json(['error' => 'Invalid token.', 'docs' => 'https://coolify.io/docs/api-reference/authorization'], 400);
2024-03-07 11:27:23 +00:00
}
2024-06-21 14:46:13 +00:00
function serialize_api_response($data)
{
if (! $data instanceof Collection) {
$data = collect($data);
}
$data = $data->sortKeys();
$created_at = data_get($data, 'created_at');
$updated_at = data_get($data, 'updated_at');
if ($created_at) {
unset($data['created_at']);
$data['created_at'] = $created_at;
}
if ($updated_at) {
unset($data['updated_at']);
$data['updated_at'] = $updated_at;
}
if (data_get($data, 'id')) {
$data = $data->prepend($data['id'], 'id');
}
return $data;
}