'1ヶ月', 2 => '2ヶ月', 3 => '3ヶ月', 4 => '6ヶ月', 5 => '12ヶ月', ]; protected $table = 'price_a'; protected $primaryKey = 'price_parkplaceid'; protected $fillable = [ 'price_parkplaceid', 'prine_name', 'price_month', 'park_id', 'psection_id', 'price_ptypeid', 'user_categoryid', 'pplace_id', 'price' ]; public static function boot() { parent::boot(); self::creating(function (Price $model) { $model->operator_id = Auth::user()->ope_id; }); } public static function search($inputs) { $query = self::query(); // 検索条件 $allowedSortColumns = [ 'price_parkplaceid', // 駐車場所ID 'park_id', // 駐輪場ID 'prine_name', // 商品名 'price_month', // 期間 'user_categoryid', // 利用者分類ID 'price', // 駐輪料金(税込) 'psection_id', // 車種区分ID 'price_ptypeid', // 駐輪分類ID 'pplace_id', // 駐車車室ID ]; // ソート指定 $sortColumn = $inputs['sort'] ?? ''; $sortType = strtolower($inputs['sort_type'] ?? 'asc'); if (in_array($sortColumn, $allowedSortColumns, true)) { if (!in_array($sortType, ['asc', 'desc'], true)) { $sortType = 'asc'; } $query->orderBy($sortColumn, $sortType); } // データ取得 return $inputs['isExport'] ? $query->get() : $query->paginate(\App\Utils::item_per_page ?? 20); } public static function getByPk($pk) { return self::find($pk); } public static function deleteByPk($arr) { return self::whereIn('price_parkplaceid', $arr)->delete(); } //TODO 駐車場所ID not found in database specs //TODO 駐車車室ID not found in database specs public function getPark() { return $this->belongsTo(Park::class, 'park_id', 'park_id')->first(); } public function getPSection() { return $this->belongsTo(Psection::class, 'psection_id', 'psection_id')->first(); } public function getPType() { return $this->belongsTo(Ptype::class, 'price_ptypeid', 'ptype_id')->first(); } public function getUserType() { return $this->belongsTo(Usertype::class, 'user_categoryid', 'user_categoryid')->first(); } }