From 11e4ce28415c6a8c7164a07abece33969ea881e8 Mon Sep 17 00:00:00 2001 From: gitadmin Date: Sat, 23 Aug 2025 00:14:46 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20app/Models/Psection.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Psection.php | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/app/Models/Psection.php b/app/Models/Psection.php index a388378..be62acb 100644 --- a/app/Models/Psection.php +++ b/app/Models/Psection.php @@ -34,8 +34,11 @@ class Psection extends Model 'psection_subject', // 車種区分名 'operator_id', // オペレータID 'created_at', // 作成日時 - 'updated_at' // 更新日時 + 'updated_at', // 更新日時 + 'psection_id' // 車種区分ID ]; + + /** * キャストする属性 @@ -48,6 +51,14 @@ class Psection extends Model 'created_at' => 'datetime', 'updated_at' => 'datetime' ]; + + + // 主キーが自動増分でない場合はfalseに設定 + public $incrementing = false; + // タイムスタンプ管理しない場合はfalseに設定 + public $timestamps = false; + + /** * 売上集計との関連 @@ -103,4 +114,30 @@ class Psection extends Model $this->psection_subject ); } + + + + + + + + + + // 新規作成時にoperator_idを自動設定(operator_idカラムがある場合のみ) + public static function boot() + { + parent::boot(); + self::creating(function (Psection $model) { + // ログインしている場合のみセット + if (\Auth::check()) { + $model->operator_id = Auth::user()->ope_id; + } + }); + } + + // 車種区分リストを取得(プルダウン用) + public static function getList() + { + return self::orderBy('psection_id')->pluck('psection_subject', 'psection_id'); + } }