KTV/app/Models/Room.php
2025-06-04 15:40:23 +08:00

84 lines
2.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Traits\LogsModelActivity;
/**
* @OA\Schema(
* schema="Room",
* type="object",
* @OA\Property(property="id", type="integer", example=16),
* @OA\Property(property="floor", type="integer", example="1"),
* @OA\Property(property="type", ref="#/components/schemas/RoomType"),
* @OA\Property(property="name", type="string", example="pc102"),
* @OA\Property(property="internal_ip", type="string", example="192.168.11.7"),
* @OA\Property(property="port", type="int", example="9000"),
* @OA\Property(property="status", ref="#/components/schemas/RoomStatus"),
* @OA\Property(property="started_at", type="string", format="date-time", example="2025-05-11T16:00:00.000000Z"),
* @OA\Property(property="ended_at", type="string", format="date-time", example=null),
* )
*/
class Room extends Model
{
/** @use HasFactory<\Database\Factories\ArtistFactory> */
use HasFactory, LogsModelActivity;
protected $fillable = [
'floor',
'type',
'name',
'internal_ip',
'port',
'is_online',
'status',
'started_at',
'ended_at',
];
protected $hidden = [
'internal_ip',
'port',
];
protected $casts = [
'floor' => 'int',
'type' => \App\Enums\RoomType::class,
'name' => 'string',
'internal_ip' =>'string',
'port' => 'int',
'is_online' => 'boolean',
'status' => \App\Enums\RoomStatus::class,
'started_at' => 'datetime',
'ended_at' => 'datetime',
];
public function str_started_at(){
$str ="Not Set";
if($this->started_at !=null){
$str = $this->started_at;
}
return $str;
}
public function str_ended_at(){
$str ="Not Set";
if($this->ended_at !=null){
$str = $this->ended_at;
}
return $str;
}
public function branch() {
return $this->belongsTo(Branch::class);
}
public function statusLogs() {
return $this->hasMany(RoomStatusLog::class);
}
}