34 lines
780 B
PHP
34 lines
780 B
PHP
<?php
|
|
|
|
namespace App\Http\Resources\Admin;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class SessionsIndexResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'ip' => $this->ip_address,
|
|
'user_agent' => $this->user_agent,
|
|
"last_activity" => $this->generateLastTime(),
|
|
];
|
|
}
|
|
|
|
private function generateLastTime()
|
|
{
|
|
$timestamp = $this->last_activity;
|
|
|
|
$carbon = Carbon::createFromTimestamp($timestamp);
|
|
return verta($carbon)->format('%Y/%m/%d - H:i');
|
|
}
|
|
}
|