manageUniversityModel.php
// this is how you create relationship between university and managefee or whatever...
public function managefees() {
return $this->hasMany(managefee::class, 'university', 'id');
}
managefee.php
public function departments() {
return $this->hasMany(uniFormDepartment::class, 'deptId', 'id');
}
public function degrees() {
return $this->hasMany(manageDegreeModel::class, 'degreeId', 'id');
}
Контроллер:
public function findUniversityDetailByCity($id) {
// I don't know why would you use Crypt here?
$uniid = Crypt::decrypt($id);
$heading = $uniid;
// you can use find(), this will fetch first model by id
$university = manageUniversityModel::find($uniid);
// instead of fetch every single row from the database, use where cluse
// and using with() allows you to load related models.
$managefees = managefee::with('departments', 'degrees')
->where('university', $uniid)
->where('eduId', 'Undergraduate')->get();
// You don't need to fetch them separately, let Laravel do it for you.
// $degree = manageDegreeModel::all(); <-- this is already loaded in managefees
// $dept = uniFormDepartment::all(); <-- this is already loaded in managefees
// I would not recommend fetching every row at the same, instead use limits and pagination.
$city = addcity::all();
$country = addCountry::all();
$edulevel = edulevel::all();
return view('findUniversityDetailByCity', compact('university', 'city', 'managefees', 'country', 'edulevel'));
}
Вид:
@foreach($managefees as $managefee)
// you don't need to check for ids manually
@foreach($managefee->departments as $department)
<h4>{{ $department->name }}</h4>
// do this only if you have same degrees in every department
@foreach($managefee->degrees as $degree)
<li>{{ $degree->name }}</li>
@endforeach
@endforeach
@endforeach
PS : научиться использовать связи с базами данных и объединения. Вы могли бы сделать структуру базы данных лучше.