This commit is contained in:
parent
2b8e26228b
commit
adcb9b9b80
@ -4,43 +4,84 @@ namespace App\Models;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
/**
|
|
||||||
* 駐輪場モデル - parkテーブル(正式モデル)
|
|
||||||
* 旧UsingStatusParkの責務を置き換え
|
|
||||||
*/
|
|
||||||
class Park extends Model
|
class Park extends Model
|
||||||
{
|
{
|
||||||
protected $table = 'park';
|
protected $table = 'park';
|
||||||
protected $primaryKey = 'park_id';
|
protected $primaryKey = 'park_id';
|
||||||
public $timestamps = true;
|
public $timestamps = true;
|
||||||
|
|
||||||
public const CREATED_AT = 'created_at';
|
/**
|
||||||
public const UPDATED_AT = 'updated_at';
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'park_name',
|
'park_name',
|
||||||
'park_ruby',
|
'park_address',
|
||||||
'park_syllabary',
|
'park_phone',
|
||||||
'park_adrs',
|
'park_description',
|
||||||
'park_close_flag',
|
'park_status',
|
||||||
'park_day',
|
'park_capacity',
|
||||||
'alert_flag',
|
'park_price',
|
||||||
'print_number',
|
'park_operating_hours',
|
||||||
'keep_alive',
|
|
||||||
'city_id',
|
|
||||||
'operator_id',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 料金設定との関連付け
|
* 駐車場検索
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
||||||
*/
|
*/
|
||||||
public function prices()
|
public static function search($inputs)
|
||||||
{
|
{
|
||||||
return $this->hasMany(PriceA::class, 'park_id', 'park_id');
|
$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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user