I have 3 tables school ,schooldetails & admission(school have multiple table), 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 (Model name is School but i am saving data to users table by using ptotected table="users")
id
name
name
mobile
city
schooldetails(School can have only one deatils)
id
school_id(foreign key of school id)
contact_person
admission(School can have multiple 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)
{{ $school->School->name}} from user table Ravi
{{ $school->SchoolDetails->contact_person}} //from school_Details table No result
{{ $school->start_date }} //from admission table date 11/22/2018
@enforeach