protected function form()
{
$form = new Form(new InfusionTicket());
$form->select('clinic_id', "诊所信息")->options(Clinic::all()->pluck('name', 'id'))->required();
$form->date('date', __('Date'))->default(date('Y-m-d'))->required();
$form->select('inject', __('Inject'))->options(['静脉输液'=>'静脉输液',"肌肉(皮下)注射"=>"肌肉(皮下)注射","抽血"=>"抽血"])->required();
$form->number('ticket', __('Ticket'))->required();
$form->select('time_index', __('时间'))->options(InfusionTicketController::$timeArray)->required();
$form->hidden('time');
$form->saving(function ($form){
$timeIndex = $form->time_index;
Log::debug('数据');
Log::debug($timeIndex);
$time = InfusionTicketController::$timeArray[$timeIndex];
Log::debug($time);
$form->time= $time;
});
//保存后回调
$form->saved(function ($form){
Log::debug("执行创建");
$model = $form->model();
$clinicId = $model->clinic_id;
$inject = $model->inject=='静脉输液'?'jmsy':'default';
$date = $model->date;
$dateFormat = Carbon::parse($date)->format('Y-m-d');
$timeIndex = $model->time_index;
$ticket = $model->ticket;
Redis::select(2);
$key = 'infusion-tickets:'.$clinicId.':'.$inject.':'.$dateFormat.':'.$timeIndex;
Log::info($key);
Redis::set($key,$ticket);
});
return $form;
在form表单中设置time为不可见(一定要设置time 不然无法保存time信息)
上述代码在保存时 添加time信息
在保存后 把对应信息 存储在redis中
protected function detail($id)
{
$show = new Show(InfusionTicket::findOrFail($id));
$show->panel()->tools(function ( \Encore\Admin\Show\Tools $tools) {
$tools->disableEdit();
});
$show->clinic('诊所信息', function ($clinic) {
$clinic->setResource('/admin/clinics/');
$clinic->field('name',__('Name'));
});
$show->field('date', __('Date'));
$show->field('inject', __('Inject'));
$show->field('ticket', __('Ticket'));
$show->field('time', __('Time'));
return $show;
}
详情页面 屏蔽“编辑”按钮
public static function boot()
{
parent::boot(); // TODO: Change the autogenerated stub
static:: deleted(function (InfusionTicket $model) {
Log::debug("模型删除");
$clinicId = $model->clinic_id;
$inject = $model->inject=='静脉输液'?'jmsy':'default';
$date = $model->date;
$dateFormat = Carbon::parse($date)->format('Y-m-d');
$timeIndex = $model->time_index;
Redis::select(2);
$key = 'infusion-tickets:'.$clinicId.':'.$inject.':'.$dateFormat.':'.$timeIndex;
Log::info($key);
Redis::del($key);
});
}
在数据模型中 增加删除回调 删除redis值