From 5b0d8b1ee57c4e9c9d54a8edd0b8f00bf79c6e04 Mon Sep 17 00:00:00 2001 From: "go.unhi" Date: Mon, 1 Sep 2025 10:15:33 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20app/Models/City.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/City.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/Models/City.php b/app/Models/City.php index 97cb3b1..ccfbd51 100644 --- a/app/Models/City.php +++ b/app/Models/City.php @@ -7,9 +7,9 @@ use Illuminate\Database\Eloquent\Model; class City extends Model { protected $table = 'city'; - public $timestamps = true; - - protected $primaryKey = 'city_id'; + protected $primaryKey = 'city_id'; + protected $keyType = 'int'; + public $incrementing = true; protected $fillable = [ 'city_id', 'city_name', @@ -23,12 +23,14 @@ class City extends Model /** * 都市のリストを取得 */ - public static function getList() + public static function getList(?int $operatorId = null): array { - return self::all(); + return static::query() + ->when($operatorId, fn ($q) => $q->where('operator_id', $operatorId)) + ->orderBy('city_name') + ->pluck('city_name', 'city_id') + ->toArray(); } - - -} +}