<?php

namespace App\Community\Actions\Docter;

use App\Models\Docter;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;

class ChangeType extends RowAction
{
    public $name = '改变类型';

    public function handle(Model $model)
    {
        $type = request('type');
        $id = $this->row->docter->id;
        $res = Docter::where(['id'=>$id])->update(['type'=>intval($type)]);
        if(!$res) return  $this->response()->error('操作失败请重试');
        return $this->response()->success('操作成功')->refresh();
    }

    public function form(){
//        1.问诊医生 2.疫苗医生 3.儿保医生)
        $type = $this->row->docter->type;
        $this->select('type','类型')->options([1=>'门诊医生',2=>'计免医生',3=>'儿保医生'])->value(intval($type));
    }

}
