63 lines
1.7 KiB
PHP
63 lines
1.7 KiB
PHP
<?php
|
||
|
||
namespace App\Models;
|
||
|
||
use Illuminate\Database\Eloquent\Model;
|
||
|
||
class Management extends Model
|
||
{
|
||
/** テーブル名 */
|
||
protected $table = 'management';
|
||
|
||
/** 主キー */
|
||
protected $primaryKey = 'management_id';
|
||
|
||
/** 自動インクリメント */
|
||
public $incrementing = true;
|
||
|
||
/** 主キー型 */
|
||
protected $keyType = 'int';
|
||
|
||
/** タイムスタンプ(created_at / updated_at) */
|
||
public $timestamps = true;
|
||
|
||
/** 一括代入を許可する項目 */
|
||
protected $fillable = [
|
||
'management_name', // 運営元名
|
||
'management_code', // 運営元コード(URL用)
|
||
'municipality_flag', // 自治体フラグ
|
||
'tel', // 電話番号
|
||
'service_time', // 受付時間
|
||
'government_approval_required', // 役所承認要否
|
||
];
|
||
|
||
/** 型キャスト */
|
||
protected $casts = [
|
||
'management_id' => 'integer',
|
||
'municipality_flag' => 'integer',
|
||
'government_approval_required' => 'integer',
|
||
'created_at' => 'datetime',
|
||
'updated_at' => 'datetime',
|
||
];
|
||
|
||
/** 自治体かどうかを判定 */
|
||
public function isMunicipality(): bool
|
||
{
|
||
return (int)$this->municipality_flag === 1;
|
||
}
|
||
|
||
/** 役所承認が必要かどうか */
|
||
public function requiresGovernmentApproval(): bool
|
||
{
|
||
return (int)$this->government_approval_required === 1;
|
||
}
|
||
|
||
/**
|
||
* この運営元に属する自治体を取得
|
||
*/
|
||
public function cities(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||
{
|
||
return $this->hasMany(City::class, 'management_id', 'management_id');
|
||
}
|
||
}
|