mercredi 13 novembre 2019

I am trying to view the details of each user separately

I have a list of tutors who have a corresponding timeslot and day, I passed the instance tutors::all() and tutor_availabilities::all() from the controller to the index, when I wish to view the tutor details with their availability timeslot and day it shows the availability timeslot and day for all tutors.

Tutor_availability Model

class Tutor_availability extends Model
{
    protected $guarded = ['id', '_token'];

     public function day()
     {
        return $this->belongsTo('App\Day', 'day_id');
     }
     public function timeslot()
     {
        return $this->belongsTo('App\Timeslot');
     }
     public function tutor()
     {
         return $this->hasOne('App\Tutor');
     }
}

Controller

public function index()
    {
        $tutors = Tutor::latest()->paginate(5);

        $tutor_availabilities = Tutor_availability::all();

        return view('tutors.index', [
            'tutors' => $tutors, 
            'tutor_availabilities' => $tutor_availabilities    
        ]);
    }

index

@foreach ($tutors as $tutor)
            <div class="media-body">
                <h5 class="m-0 mt-2 my-1" style="font-family:Roboto-Regular; ">  </h5>
                <hr class="m-0 p-0">
                <h6 class="mt-1 text-muted">   
                    <i class="small material-icons " style="font-size: 15px; color: #4caf50;"> verified_user</i>  
                    <i class="small material-icons pr-1" style="font-size: 15px;"> school</i>
                
                </h6>   
                <p class="d-flex p-0 m-0" style="height: 6rem;">
                 
                </p >
                <div class="d-sm-flex flex-row-reverse">
                    <button class="btn btn-primary ml-3" data-toggle="modal" data-target="#cardOne"> Profile </button>
                    <button class="btn btn-success"> Call </button>
                </div>
            </div>
            <div class="modal-body">
                <table class="table table-hover">
                    @foreach ($tutor_availabilities as $tutor_availability)
                        //@$tutor_availability::findOrFail($tutor->id) 
                        //@if($tutor_availability->tutor_id == $tutor->id)
                      <thead>
                        <tr>
                          <th scope="col">Name</th>
                          <th scope="col">Days</th>
                          <th scope="col">Timings</th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr>
                          <td></td>
                          <td></td>
                          <td></td>
                        </tr>
                      </tbody>
                      //@endif
                    @endforeach
                </table>
              </div>
@endforeach

This is the output I got: https://i.imgur.com/heoyWpZ.png which basically view the latest tutor's details only



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire