{"id":337,"date":"2021-03-05T07:06:44","date_gmt":"2021-03-05T07:06:44","guid":{"rendered":"http:\/\/robinluo.top\/?p=337"},"modified":"2021-03-05T07:07:19","modified_gmt":"2021-03-05T07:07:19","slug":"laravel-admin-form","status":"publish","type":"post","link":"https:\/\/robinluo.top\/?p=337","title":{"rendered":"laravel-admin form"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>  protected function form()\r\n    {\r\n\r\n        $form = new Form(new InfusionTicket());\r\n\r\n        $form->select('clinic_id', \"\u8bca\u6240\u4fe1\u606f\")->options(Clinic::all()->pluck('name', 'id'))->required();\r\n        $form->date('date', __('Date'))->default(date('Y-m-d'))->required();\r\n        $form->select('inject', __('Inject'))->options(&#91;'\u9759\u8109\u8f93\u6db2'=>'\u9759\u8109\u8f93\u6db2',\"\u808c\u8089\uff08\u76ae\u4e0b\uff09\u6ce8\u5c04\"=>\"\u808c\u8089\uff08\u76ae\u4e0b\uff09\u6ce8\u5c04\",\"\u62bd\u8840\"=>\"\u62bd\u8840\"])->required();\r\n        $form->number('ticket', __('Ticket'))->required();\r\n        $form->select('time_index', __('\u65f6\u95f4'))->options(InfusionTicketController::$timeArray)->required();\r\n        $form->hidden('time');\r\n\r\n        $form->saving(function ($form){\r\n\r\n            $timeIndex = $form->time_index;\r\n            Log::debug('\u6570\u636e');\r\n            Log::debug($timeIndex);\r\n            $time = InfusionTicketController::$timeArray&#91;$timeIndex];\r\n            Log::debug($time);\r\n            $form->time= $time;\r\n        });\r\n        \/\/\u4fdd\u5b58\u540e\u56de\u8c03\r\n        $form->saved(function ($form){\r\n            Log::debug(\"\u6267\u884c\u521b\u5efa\");\r\n            $model = $form->model();\r\n            $clinicId = $model->clinic_id;\r\n            $inject = $model->inject=='\u9759\u8109\u8f93\u6db2'?'jmsy':'default';\r\n            $date = $model->date;\r\n            $dateFormat = Carbon::parse($date)->format('Y-m-d');\r\n            $timeIndex = $model->time_index;\r\n            $ticket = $model->ticket;\r\n            Redis::select(2);\r\n            $key = 'infusion-tickets:'.$clinicId.':'.$inject.':'.$dateFormat.':'.$timeIndex;\r\n            Log::info($key);\r\n            Redis::set($key,$ticket);\r\n\r\n        });\r\n\r\n        return $form;\r\n  <\/code><\/pre>\n\n\n\n<p>\u5728form\u8868\u5355\u4e2d\u8bbe\u7f6etime\u4e3a\u4e0d\u53ef\u89c1\uff08\u4e00\u5b9a\u8981\u8bbe\u7f6etime \u4e0d\u7136\u65e0\u6cd5\u4fdd\u5b58time\u4fe1\u606f\uff09<\/p>\n\n\n\n<p>\u4e0a\u8ff0\u4ee3\u7801\u5728\u4fdd\u5b58\u65f6 \u6dfb\u52a0time\u4fe1\u606f<\/p>\n\n\n\n<p>\u5728\u4fdd\u5b58\u540e \u628a\u5bf9\u5e94\u4fe1\u606f \u5b58\u50a8\u5728redis\u4e2d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> protected function detail($id)\r\n    {\r\n        $show = new Show(InfusionTicket::findOrFail($id));\r\n        $show->panel()->tools(function ( \\Encore\\Admin\\Show\\Tools $tools) {\r\n            $tools->disableEdit();\r\n        });\r\n\r\n        $show->clinic('\u8bca\u6240\u4fe1\u606f', function ($clinic)  {\r\n            $clinic->setResource('\/admin\/clinics\/');\r\n            $clinic->field('name',__('Name'));\r\n        });\r\n        $show->field('date', __('Date'));\r\n        $show->field('inject', __('Inject'));\r\n        $show->field('ticket', __('Ticket'));\r\n        $show->field('time', __('Time'));\r\n\r\n        return $show;\r\n    }<\/code><\/pre>\n\n\n\n<p>\u8be6\u60c5\u9875\u9762 \u5c4f\u853d\u201c\u7f16\u8f91\u201d\u6309\u94ae<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> public static function boot()\r\n    {\r\n        parent::boot(); \/\/ TODO: Change the autogenerated stub\r\n        static:: deleted(function (InfusionTicket $model) {\r\n            Log::debug(\"\u6a21\u578b\u5220\u9664\");\r\n            $clinicId = $model->clinic_id;\r\n            $inject = $model->inject=='\u9759\u8109\u8f93\u6db2'?'jmsy':'default';\r\n            $date = $model->date;\r\n            $dateFormat = Carbon::parse($date)->format('Y-m-d');\r\n            $timeIndex = $model->time_index;\r\n            Redis::select(2);\r\n            $key = 'infusion-tickets:'.$clinicId.':'.$inject.':'.$dateFormat.':'.$timeIndex;\r\n            Log::info($key);\r\n            Redis::del($key);\r\n        });\r\n    }<\/code><\/pre>\n\n\n\n<p>\u5728\u6570\u636e\u6a21\u578b\u4e2d \u589e\u52a0\u5220\u9664\u56de\u8c03 \u5220\u9664redis\u503c<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728form\u8868\u5355\u4e2d\u8bbe\u7f6etime\u4e3a\u4e0d\u53ef\u89c1\uff08\u4e00\u5b9a\u8981\u8bbe\u7f6etime \u4e0d\u7136\u65e0\u6cd5\u4fdd\u5b58time\u4fe1\u606f\uff09 \u4e0a\u8ff0\u4ee3\u7801\u5728\u4fdd\u5b58\u65f6 \u6dfb\u52a0time\u4fe1\u606f \u5728\u4fdd\u5b58\u540e \u628a\u5bf9\u5e94\u4fe1\u606f \u5b58\u50a8\u5728redis\u4e2d \u8be6\u60c5\u9875\u9762 \u5c4f\u853d\u201c\u7f16\u8f91\u201d\u6309\u94ae \u5728\u6570\u636e\u6a21\u578b\u4e2d \u589e\u52a0\u5220\u9664\u56de\u8c03 \u5220\u9664redis\u503c<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[10,51],"_links":{"self":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/337"}],"collection":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=337"}],"version-history":[{"count":1,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/337\/revisions"}],"predecessor-version":[{"id":338,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/337\/revisions\/338"}],"wp:attachment":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}