<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Ptype extends Model
{

    /**
     * 主キー配列で一括削除
     */
    public static function deleteByPk($arr)
    {
        return self::whereIn('ptype_id', $arr)->delete();
    }

    /**
     * 主キーで1件取得
     */
    public static function getByPk($pk)
    {
        return self::find($pk);
    }
    protected $table = 'ptype';
    protected $primaryKey = 'ptype_id';
    public $timestamps = true;

    public const CREATED_AT = 'created_at';
    public const UPDATED_AT = 'updated_at';

    protected $fillable = [
        'ptype_subject',
        'ptype_remarks',
        'operator_id',
        'floor_sort',
    ];

    public static function search($inputs)
    {
        $list = self::query();
        if (!empty($inputs['isMethodPost'])) {
            // 必要に応じて検索条件を追加
        }
        if (!empty($inputs['sort'])) {
            $list->orderBy($inputs['sort'], $inputs['sort_type'] ?? 'asc');
        }
        if (!empty($inputs['isExport'])) {
            return $list->get();
        } else {
            return $list->paginate(20);
        }
    }

    public static function getList()
    {
        return self::pluck('ptype_subject', 'ptype_id');
    }


    public function prices()
    {
        return $this->hasMany(PriceA::class, 'price_ptypeid', 'ptype_id');
    }
}




