更新 app/Models/Psection.php
All checks were successful
Deploy preview (main_ou) / deploy (push) Successful in 11s

This commit is contained in:
gitadmin 2025-08-23 00:15:24 +09:00
parent 66ad57252f
commit be362aeb7b

View File

@ -5,22 +5,124 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
/**
* 車種区分モデル - 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', // 更新日時
'psection_id' // 車種区分ID
];
/**
* キャストする属性
*
* @var array
*/
protected $casts = [
'psection_id' => 'integer',
'operator_id' => 'integer',
'created_at' => 'datetime',
'updated_at' => 'datetime'
];
// 主キーが自動増分でない場合はfalseに設定
public $incrementing = false;
// タイムスタンプ管理しない場合はfalseに設定
public $timestamps = false;
// 一括代入可能なカラム
protected $fillable = [
'psection_id', // 車種区分ID
'psection_subject', // 車種区分名
];
/**
* 売上集計との関連
*
* @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
);
}
// 新規作成時にoperator_idを自動設定operator_idカラムがある場合のみ
public static function boot()