Room 時間格式錯誤 重新調整 20250627
This commit is contained in:
parent
b6b0173ae4
commit
a4d4b7569a
10
.env.example
10
.env.example
@ -23,13 +23,13 @@ LOG_LEVEL=debug
|
||||
|
||||
#DB_CONNECTION=sqlite
|
||||
DB_CONNECTION=mariadb
|
||||
DB_HOST=127.0.0.1
|
||||
DB_HOST=mariadb
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=KaraokeKingpin
|
||||
DB_USERNAME=KaraokeKingpin
|
||||
DB_PASSWORD=ESM7yTPMnavFmbBH
|
||||
|
||||
SESSION_DRIVER=database
|
||||
SESSION_DRIVER=redis
|
||||
SESSION_LIFETIME=120
|
||||
SESSION_ENCRYPT=false
|
||||
SESSION_PATH=/
|
||||
@ -37,15 +37,15 @@ SESSION_DOMAIN=null
|
||||
|
||||
BROADCAST_CONNECTION=log
|
||||
FILESYSTEM_DISK=local
|
||||
QUEUE_CONNECTION=database
|
||||
QUEUE_CONNECTION=redis
|
||||
|
||||
CACHE_STORE=database
|
||||
CACHE_STORE=redis
|
||||
# CACHE_PREFIX=
|
||||
|
||||
MEMCACHED_HOST=127.0.0.1
|
||||
|
||||
REDIS_CLIENT=phpredis
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_HOST=redis
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
|
@ -314,7 +314,7 @@ class RoomControlController extends Controller
|
||||
$response = (new MachineStatusForwarder(
|
||||
$branch->external_ip,
|
||||
"/api/room/receiveSwitch",
|
||||
$room->toArray()
|
||||
(new RoomResource($room))->toArray(request())
|
||||
))->forward();
|
||||
return $validated['command']==='error' ? ApiResponse::error('機房控制失敗') : ApiResponse::success($room);
|
||||
}
|
||||
|
28
app/Http/Resources/RoomResource.php
Normal file
28
app/Http/Resources/RoomResource.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class RoomResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$array = parent::toArray($request);
|
||||
$array['started_at'] = $this->formatTaipei($this->started_at);
|
||||
$array['ended_at'] = $this->formatTaipei($this->ended_at);
|
||||
return $array;
|
||||
}
|
||||
|
||||
protected function formatTaipei(?Carbon $value): ?string
|
||||
{
|
||||
return $value ? $value->timezone('Asia/Taipei')->format('Y-m-d H:i:s') : null;
|
||||
}
|
||||
}
|
@ -80,18 +80,4 @@ class Room extends Model
|
||||
public function statusLogs() {
|
||||
return $this->hasMany(RoomStatusLog::class);
|
||||
}
|
||||
public function toArray()
|
||||
{
|
||||
$array = parent::toArray();
|
||||
|
||||
if ($this->started_at) {
|
||||
$array['started_at'] = $this->started_at->timezone('Asia/Taipei')->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
if ($this->ended_at) {
|
||||
$array['ended_at'] = $this->ended_at->timezone('Asia/Taipei')->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user