dimanche 13 janvier 2019

How to fetch all data from 3 tables with condition in laravel?

I have 3 tables school ,schooldetails & admission, and i want to get all data in index page how can i do that , i am getting data of school and admission table due to relationship but not of school details kindly check it and help

school

id
name
name
mobile
city


schooldetails
id
school_id(foreign key of school id)
contact_person

admission

id
school_id(foreign key of school_deatils id)
admission_classes
start_date
end_date

My function
public function schoolslist($class='', $city='')
        {
        $schools = Admission::where('admission_classes', 'like', "%{$class}%")->where('status', '1')->orderBy('id','desc')->whereHas('school', function($query) use($city) {
    $query->where('city', 'like', $city);
})->paginate(10);
          return view('frontend.index',compact('schools'));

        }
        my Admission model
        public function School()
    {
        return $this->belongsTo('App\School');
    }
    public function SchoolDetails()
    {
        return $this->belongsTo('App\SchoolDetails');
    }
        
        My view
         @foreach($schools as $i => $school)
          from user table Ravi
        //from school_Details table  No result 
          //from admission table  date 11/22/2018
         @enforeach


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire