krgm.so-manager-dev.com/app/Models/Device.php

83 lines
2.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* デバイスモデル - deviceテーブル
*
* ハードウェアデバイス(印刷機等)の情報を管理するモデル
* batch_logテーブルとの関連でバッチ処理ログに使用される
*/
class Device extends Model
{
protected $table = 'device';
protected $primaryKey = 'device_id';
public $timestamps = true;
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'park_id', // 駐輪場ID
'device_type', // デバイスタイプ
'device_subject', // デバイス件名
'device_identifier', // デバイス識別子
'device_work', // デバイス作業
'device_workstart', // 作業開始日
'device_replace', // 交換日
'device_remarks', // 備考
'operator_id' // オペレータID
];
protected $casts = [
'device_workstart' => 'date',
'device_replace' => 'date',
];
/**
* 駐輪場との関連付け
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function park()
{
// UsingStatus系は廃止。正式モデル Park を使用。
return $this->belongsTo(Park::class, 'park_id', 'park_id');
}
/**
* バッチログとの関連付けbatch_logテーブル
* 統一BatchLogで管理される
*
* @return \Illuminate\Database\Query\Builder
*/
public function batchLogs()
{
return \DB::table('batch_log')
->where('parameters->device_id', $this->device_id);
}
/**
* デバイスIDの存在確認
*
* @param int $deviceId デバイスID
* @return bool 存在するかどうか
*/
public static function exists(int $deviceId): bool
{
return self::where('device_id', $deviceId)->exists();
}
/**
* デバイス情報を取得
*
* @param int $deviceId デバイスID
* @return Device|null デバイス情報
*/
public static function findByDeviceId(int $deviceId): ?Device
{
return self::where('device_id', $deviceId)->first();
}
}