krgm.so-manager-dev.com/app/Models/Park.php
SongSong cf95babf8e
All checks were successful
Deploy previews (main_*) / preview (push) Successful in 10s
SWA-63駐輪車室マスタ作成
2025-08-21 20:50:27 +09:00

88 lines
2.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Park extends Model
{
protected $table = 'park';
protected $primaryKey = 'park_id';
public $timestamps = true;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'park_name',
'park_address',
'park_phone',
'park_description',
'park_status',
'park_capacity',
'park_price',
'park_operating_hours',
];
/**
* 駐車場検索
*/
public static function search($inputs)
{
$query = self::query();
// 検索条件の適用
if (!empty($inputs['park_name'])) {
$query->where('park_name', 'like', '%' . $inputs['park_name'] . '%');
}
if (!empty($inputs['park_address'])) {
$query->where('park_address', 'like', '%' . $inputs['park_address'] . '%');
}
if (isset($inputs['park_status']) && $inputs['park_status'] !== '') {
$query->where('park_status', $inputs['park_status']);
}
// ソート
if (!empty($inputs['sort'])) {
$sortType = !empty($inputs['sort_type']) ? $inputs['sort_type'] : 'asc';
$query->orderBy($inputs['sort'], $sortType);
} else {
$query->orderBy('park_id', 'desc');
}
// エクスポート用の場合はページネーションしない
if (!empty($inputs['isExport'])) {
return $query->get();
}
// ページネーションUtilsクラスの定数を使用
return $query->paginate(\App\Utils::item_per_page);
}
/**
* IDで駐車場を取得
*/
public static function getParkById($id)
{
return self::find($id);
}
/**
* 駐車場リストを取得(ドロップダウン用)
*/
public static function getList()
{
return self::pluck('park_name', 'park_id')->toArray();
}
/**
* 定期契約とのリレーション
*/
public function regularContracts()
{
return $this->hasMany(RegularContract::class, 'park_id', 'park_id');
}
}