在数据库中添加 json 类型不起作用

我想在我用 Laravel 制作的项目中显示医生的可用性,使用 json 类型显示早上和下午的可用性,如下所示:Monday_morning:["8:30" ; “12:30”] 所以一开始它是工作的,但之后它只给我看这个:Monday_morning:“12:30”最后一次添加


所以这是我的控制器:


 'lun_mat1' => 'nullable',

            'mar_mat1' => 'nullable',

            'mar_ap1' => 'nullable',

            'mer_mat1' => 'nullable',

            'mer_ap1' => 'nullable',

            'jeu_mat1' => 'nullable',

            'jeu_ap1' => 'nullable',

            'ven_mat1' => 'nullable',

            'ven_ap1' => 'nullable',

            'sam_mat1' => 'nullable',

        $medecin= new doc() ;


        $medecin->Lun_mat_de=$request->input('lun_mat1');

        $medecin->Lun_apres_a=$request->input('lun_ap1');


        $medecin->Mar_mat_de=$request->input('mar_mat1');

        $medecin->Mar_apres_a=$request->input('mar_ap1');


        $medecin->Mer_mat_de=$request->input('mer_mat1');

        $medecin->Mer_apres_a=$request->input('mer_ap1');


        $medecin->Jeu_mat_de=$request->input('jeu_mat1');

        $medecin->Jeu_apres_a=$request->input('jeu_ap1');


        $medecin->Vend_mat_de=$request->input('ven_mat1');

        $medecin->Vend_apres_a=$request->input('ven_ap1');


        $medecin->Sam_mat_de=$request->input('sam_mat1');


        $medecin->save();

return redirect()->back()->withSuccess('medecin ajouter' ) ; 

这是模型:


 protected  $table = 'doctors' ;

    protected $primaryKey = 'ID';

    protected $fillable = [

        'ID' ,

        'Photo' ,

        'demande',];


        protected $casts = [


        'Lun_mat_de' =>'array',

        'Lun_apres_a' =>'array',


        'Mar_mat_de' =>'array',

        'Mar_apres_a' => 'array', 


        'Mer_mat_de' =>'array',

        'Mer_apres_a' =>'array',


        'Jeu_mat_de' => 'array',

        'Jeu_apres_a' => 'array',


        'Vend_mat_de' => 'array' , 

        'Vend_apres_a' => 'array',


        'Sam_mat_de' => 'array',



        ];


皈依舞
浏览 162回答 1
1回答

肥皂起泡泡

我认为你面临的问题是在这里:<div class="col-4">&nbsp; &nbsp;<label> Monday morning </label>&nbsp; &nbsp;<div class="row">&nbsp; &nbsp; &nbsp; <div class="col">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="time"&nbsp; name="lun_mat1" /> /* input name is supposed to be like this lun_mat1[] */&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; <div class="col">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="time"&nbsp; name="lun_mat1" /> /* input name is supposed to be like this lun_mat1[] */&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </div></div>这是错误的,因为你想将 lun_mat1 作为数组获取,但是你上面的两个输入名称是相同的,它应该更改为这个以便在发布到控制器时检索数组值:<div class="col-4">&nbsp; &nbsp;<label> Monday morning </label>&nbsp; &nbsp;<div class="row">&nbsp; &nbsp; &nbsp; <div class="col">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="time"&nbsp; name="lun_mat1[]" />&nbsp;&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; <div class="col">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="time"&nbsp; name="lun_mat1[]" />&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </div></div>有了这个,您可以将此规则应用于所有输入,如果您想在发布到控制器时检索数组数据,请[]在输入名称后添加
打开App,查看更多内容
随时随地看视频慕课网APP