All checks were successful
Deploy preview (main_go) / deploy (push) Successful in 14s
- SHJ-9: 日次売上集計処理 - SHJ-10: 年次月次売上集計処理 - SHJ-6: サーバ死活監視処理 - 各種モデルサービスコマンド追加 - earnings_summary, device, hardware_check_log, print_job_log テーブル用SQL追加
107 lines
2.2 KiB
PHP
107 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* 車種区分モデル - psectionテーブル
|
|
*
|
|
* 駐輪場の車種区分マスタデータを管理
|
|
*/
|
|
class Psection extends Model
|
|
{
|
|
/**
|
|
* テーブル名
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'psection';
|
|
|
|
/**
|
|
* プライマリキー
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $primaryKey = 'psection_id';
|
|
|
|
/**
|
|
* 一括代入可能な属性
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'psection_subject', // 車種区分名
|
|
'operator_id', // オペレータID
|
|
'created_at', // 作成日時
|
|
'updated_at' // 更新日時
|
|
];
|
|
|
|
/**
|
|
* キャストする属性
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'psection_id' => 'integer',
|
|
'operator_id' => 'integer',
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime'
|
|
];
|
|
|
|
/**
|
|
* 売上集計との関連
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function earningsSummaries()
|
|
{
|
|
return $this->hasMany(EarningsSummary::class, 'psection_id', 'psection_id');
|
|
}
|
|
|
|
/**
|
|
* 定期契約との関連
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function regularContracts()
|
|
{
|
|
return $this->hasMany(RegularContract::class, 'psection_id', 'psection_id');
|
|
}
|
|
|
|
/**
|
|
* アクティブな車種区分一覧を取得
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Collection
|
|
*/
|
|
public static function getActivePsections()
|
|
{
|
|
return self::orderBy('psection_id')->get();
|
|
}
|
|
|
|
/**
|
|
* 車種区分名で検索
|
|
*
|
|
* @param string $subject 車種区分名
|
|
* @return Psection|null
|
|
*/
|
|
public static function findBySubject(string $subject): ?Psection
|
|
{
|
|
return self::where('psection_subject', $subject)->first();
|
|
}
|
|
|
|
/**
|
|
* 文字列表現
|
|
*
|
|
* @return string
|
|
*/
|
|
public function __toString(): string
|
|
{
|
|
return sprintf(
|
|
'Psection[ID:%d, Subject:%s]',
|
|
$this->psection_id,
|
|
$this->psection_subject
|
|
);
|
|
}
|
|
}
|