krgm.so-manager-dev.com/app/Models/RegularType.php
kin.rinzen 22e278b5ad
All checks were successful
Deploy previews (main_*) / preview (push) Successful in 9s
定期種別マスタのルートとコントローラーを追加し、関連するビューを更新
2025-08-21 19:46:22 +09:00

78 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Support\Facades\Auth;
use Illuminate\Database\Eloquent\Model;
use App\Models\City;
use App\Utils;
class RegularType extends Model
{
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
const RegularClass = [
'有効',
'無効',
];
protected $table = 'regular_type';
protected $primaryKey = 'regular_type_id';
protected $fillable = [
'regular_type_id',
'city_id',
'regular_class_1',
'regular_class_2',
'regular_class_3',
'regular_class_6',
'regular_class_12',
'memo',
];
public static function boot()
{
parent::boot();
self::creating(function (RegularType $model) {
$model->operator_id = Auth::user()->ope_id;
});
}
public static function search($inputs)
{
$list = self::query();
if ($inputs['isMethodPost']) {
// 検索条件
}
if ($inputs['sort']) {
$list->orderBy($inputs['sort'], $inputs['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('regular_type_id', $arr)->delete();
}
public function getCity()
{
return $this->belongsTo(City::class, 'city_id', 'city_id')->first();
}
}