'1ヶ月', 2 => '2ヶ月', 3 => '3ヶ月', 4 => '6ヶ月', 5 => '12ヶ月', ]; protected $table = 'price_a'; protected $primaryKey = 'price_parkplaceid'; protected $fillable = [ '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) { $list = self::query(); // 只有在sort是有效字段时才排序 $allowedSortColumns = [ 'price_parkplaceid', 'prine_name', 'price_month', 'park_id', 'psection_id', 'price_ptypeid', 'user_categoryid', 'pplace_id', 'price' ]; $sort_column = $inputs['sort'] ?? ''; $sort_type = strtolower($inputs['sort_type'] ?? 'asc'); if (in_array($sort_column, $allowedSortColumns)) { if (!in_array($sort_type, ['asc', 'desc'])) { $sort_type = 'asc'; } $list->orderBy($sort_column, $sort_type); } if ($inputs['isExport']) { $list = $list->get(); } else { $list = $list->paginate(Utils::item_per_page); } return $list; } 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(); } }