All checks were successful
Deploy previews (main_*) / preview (push) Successful in 10s
88 lines
2.2 KiB
PHP
88 lines
2.2 KiB
PHP
<?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');
|
||
}
|
||
}
|