krgm.so-manager-dev.com/app/Models/City.php
OU.ZAIKOU 13d2ecfceb
All checks were successful
Deploy main / deploy (push) Successful in 25s
【ログイン】二重認証実装
2026-01-21 22:37:38 +09:00

67 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class City extends Model
{
protected $table = 'city';
protected $primaryKey = 'city_id';
protected $keyType = 'int';
public $incrementing = true;
protected $fillable = [
'city_id',
'city_name',
'print_layout',
'city_user',
'city_remarks',
'management_id',
'created_at',
'updated_at',
];
/**
* 都市のリストを取得
*/
public static function getList(?int $operatorId = null): array
{
return static::query()
->when($operatorId, fn($q) => $q->where('operator_id', $operatorId))
->orderBy('city_name')
->pluck('city_name', 'city_id')
->toArray();
}
/**
* この都市が属する運営元を取得
*/
public function management(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Management::class, 'management_id', 'management_id');
}
/**
* 自治体別ダッシュボード画面の表示
*
* 指定された city_id に基づいて都市情報を取得し、
* 該当データが存在しない場合は 404 エラーを返します。
* 正常に取得できた場合は、ダッシュボード画面を表示します。
*
* @param int $city_id 都市ID
* @return \Illuminate\View\View
*/
public function dashboard($city_id)
{
$city = City::find($city_id);
if (!$city) {
abort(404);
}
// ここに自治体別ダッシュボードの処理を書く
return view('admin.CityMaster.dashboard', [
'city' => $city,
]);
}
}