All checks were successful
Deploy previews (main_*) / preview (push) Successful in 10s
81 lines
1.7 KiB
PHP
81 lines
1.7 KiB
PHP
<?php
|
||
|
||
namespace App\Models;
|
||
|
||
use Illuminate\Support\Facades\Auth;
|
||
use App\Utils;
|
||
use Illuminate\Database\Eloquent\Model;
|
||
|
||
class Pplace extends Model
|
||
{
|
||
const CREATED_AT = 'created_at';
|
||
const UPDATED_AT = 'updated_at';
|
||
const PERPAGE = 50;
|
||
|
||
protected $table = 'pplace';
|
||
protected $primaryKey = 'pplace_id';
|
||
|
||
protected $fillable = [
|
||
'pplace_number',
|
||
'pplace_remarks',
|
||
'operator_id'
|
||
];
|
||
/*
|
||
public static function boot()
|
||
{
|
||
parent::boot();
|
||
self::creating(function (Pplace $model) {
|
||
if (Auth::check()) {
|
||
$model->operator_id = Auth::user()->ope_id;
|
||
}
|
||
});
|
||
}
|
||
*
|
||
/**
|
||
* 一覧検索・ソート処理
|
||
*/
|
||
public static function search($inputs)
|
||
{
|
||
$list = self::query();
|
||
|
||
if ($inputs['isMethodPost'] ?? false) {
|
||
// ここで条件検索処理を追加可能(例: $list->where(...);)
|
||
}
|
||
|
||
// 並び順
|
||
if (!empty($inputs['sort'])) {
|
||
$list->orderBy($inputs['sort'], $inputs['sort_type'] ?? 'asc');
|
||
}
|
||
|
||
if ($inputs['isExport'] ?? false) {
|
||
return $list->get();
|
||
} else {
|
||
return $list->paginate(Utils::item_per_page);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 主キーで取得
|
||
*/
|
||
public static function getByPk($pk)
|
||
{
|
||
return self::find($pk);
|
||
}
|
||
|
||
/**
|
||
* 主キー配列で一括削除
|
||
*/
|
||
public static function deleteByPk($arr)
|
||
{
|
||
return self::whereIn('pplace_id', $arr)->delete();
|
||
}
|
||
|
||
/**
|
||
* 選択リスト取得用(フォーム等)
|
||
*/
|
||
public static function getList()
|
||
{
|
||
return self::pluck('pplace_number', 'pplace_id');
|
||
}
|
||
}
|