0

i want to show in my project made with Laravel the avaibility of the doctor , with type json to show the avaibility in the morning and in the afternoon like this : Monday_morning:["8:30" ; "12:30"] So at first it was working , but after it just show me this one : Monday_morning: "12:30" with the last time added

So this is my controller :

 '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' ) ; 

And this is the model :

 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',


        ];

and finaly this is the form :

 <p>Avaiability of doctor</p>
  <div class="row">
<div class="col-4">
  <label> Monday morning </label>
  <div class="row">
  <div class="col">
  <input type="time"  name="lun_mat1" /> 
  </div>
  <div class="col">
  <input type="time"  name="lun_mat1" />
  </div></div>
  </div>
  <div class="col-4">
  <label>Monday afternoon</label>
  <div class="row">
  <div class="col">
  <input type="time"  name="lun_ap1" /> 
  </div>
  <div class="col">
  <input type="time"  name="lun_ap1" />
  </div>
  </div> </div>
  <div class="col-4">
  <input type="checkbox"  name="rememberMe"> Fermer
</div>
</div>
 <hr color="#61BDE6">
 <div class="row">
<div class="col-4">
  <label> Tuesday morning </label>
  <div class="row">
  <div class="col">
  <input type="time"  name="mar_mat1" /> 
  </div>
  <div class="col">
  <input type="time"  name="mar_mat1" />
  </div></div>
  </div>
  <div class="col-4">
  <label> Tuesday afternoon </label>
  <div class="row">
  <div class="col">
  <input type="time"  name="mar_ap1" /> 
  </div>
  <div class="col">
  <input type="time"  name="mar_ap1" />
  </div></div>
  </div>
  <div class="col-4">
  <input type="checkbox"  name="rememberMe"> Fermer
</div>
  </div>
  <hr color="#61BDE6">
  <div class="row">
<div class="col-4">
  <label> Wedensday Morning </label>
  <div class="row">
  <div class="col">
  <input type="time"  name="mer_mat1" /> 
  </div>
  <div class="col">
  <input type="time"  name="mer_mat1" />
  </div></div>
  </div>
  <div class="col-4">
  <label> Wedensday afternoon </label>
  <div class="row">
  <div class="col">
  <input type="time"  name="mer_ap1" /> 
  </div>
  <div class="col">
  <input type="time"  name="mer_ap1" />
  </div></div> </div>
  <div class="col-4">
  <input type="checkbox"  name="rememberMe"> Fermer
</div>
  </div>
  <hr color="#61BDE6">

  <div class="row">
<div class="col-4">
  <label> Thursday morning </label>
  <div class="row">
  <div class="col">
  <input type="time"  name="jeu_mat1" /> 
  </div>
  <div class="col">
  <input type="time"  name="jeu_mat1" />
  </div></div>
  </div>
  <div class="col-4">
  <label> Thursday afternoon</label>
  <div class="row">
  <div class="col">
  <input type="time"  name="jeu_ap1" /> 
  </div>
  <div class="col">
  <input type="time"  name="jeu_ap1" />
  </div></div>
  </div>
  <div class="col-4">
  <input type="checkbox"  name="rememberMe"> Fermer
</div>
  </div>
  <hr color="#61BDE6">
  <div class="row">
<div class="col-4">
  <label> friday morning </label>
  <div class="row">
  <div class="col">
  <input type="time"  name="ven_mat1" /> 
  </div>
  <div class="col-6">
  <input type="time" name="ven_mat1" />
  </div></div>
  </div>
  <div class="col-4">
  <label> Friday afternoon </label>
  <div class="row">
  <div class="col">
  <input type="time" name="ven_ap1" /> 
  </div>
  <div class="col">
  <input type="time"  name="ven_ap1" />
  </div></div>
  </div> 
  <div class="col-4">
  <input type="checkbox"  name="rememberMe"> Fermer
</div>
  </div>
  <hr color="#61BDE6">

  <div class="row">
   <div class="col-4">
  <label> Saturday morning </label>
  <div class="row">
  <div class="col">
  <input type="time" name="sam_mat1" /> 
  </div>
  <div class="col">
  <input type="time"  name="sam_mat1" />
  </div></div>
  </div>
  <div class="col-4">
  <input type="checkbox"  name="rememberMe"> Fermer
</div>
  </div>
  </div> </div>
</section>

1 Answer 1

1

I think problem you are facing is here:

<div class="col-4">
   <label> Monday morning </label>
   <div class="row">
      <div class="col">
          <input type="time"  name="lun_mat1" /> /* input name is supposed to be like this lun_mat1[] */
      </div>
      <div class="col">
          <input type="time"  name="lun_mat1" /> /* input name is supposed to be like this lun_mat1[] */
      </div>
    </div>
</div>

It's wrong because you want to get lun_mat1 as array, but both of your above input name is the same, it should be changed to this for retrieving array value when posting to controller:

<div class="col-4">
   <label> Monday morning </label>
   <div class="row">
      <div class="col">
          <input type="time"  name="lun_mat1[]" /> 
      </div>
      <div class="col">
          <input type="time"  name="lun_mat1[]" />
      </div>
    </div>
</div>

With this, you can apply this rule for all of your input, if you want to retrieve array data when posting to controller, add [] after the input name

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.