diff --git a/app/Models/Usertype.php b/app/Models/Usertype.php index 4f50f72..ac73bd2 100644 --- a/app/Models/Usertype.php +++ b/app/Models/Usertype.php @@ -3,22 +3,64 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Auth; class Usertype extends Model { + const CREATED_AT = 'created_at'; + const UPDATED_AT = 'updated_at'; + const PERPAGE = 50; + protected $table = 'usertype'; - // プライマリーキーはLaravelのデフォルト('id')を使用 - public $timestamps = true; + protected $primaryKey = 'user_categoryid'; protected $fillable = [ - // 実際のカラム名が不明のため、一旦空にする + 'print_name', + 'usertype_money', + 'usertype_remarks' ]; - /** - * ユーザータイプのリストを取得 - */ - public static function getList() + public static function boot() { - return self::all(); + parent::boot(); + self::creating(function (Usertype $model) { + $model->operator_id = Auth::user()->ope_id; + }); } -} + + public static function search($inputs) + { + $list = self::query(); + if ($inputs['isMethodPost']) { + + } + // Sort + 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('user_categoryid', $arr)->delete(); + } + + //TODO 利用者分類ID not found in database specs + + //TODO 利用者分類名 not found in database specs + public static function getList(){ + return self::pluck('print_name','user_categoryid'); + } + +} \ No newline at end of file