I am adding a new feature to my search directory. The profiles contain variables from the database so there is a lot of data being fetched from the same database table. There is one data, however, that is being put into a separate table because it can't fit in the same table as the other data, but I don't know how to create the controller for it.
Here is the controller for the profile page (the snippet that controls the view):
//view school
public function viewschool($url){
$url ='schools/'.$url;
if(count(School::where('url', '=', $url)->first())<>1){
return redirect()->back();
}
$sch=School::where('url', '=', $url)->first();
$articles=posts::where('post_type','article')->where('school',$sch->name)->take(3)->get();
$news=posts::where('post_type','news')->where('school',$sch->name)->take(3)->get();
$others=posts::where('post_type','news')->take(3)->get();
return view('school-info')
->with(array('sch' => $sch,'school_articles'=>$articles,'school_news'=>$news,'others'=>$others));
}
The new data are the school courses. the database table for courses contain columns for school ID (basically the courses are matched up to the ID of the school name they belong to in the schools table) as well as other data such as duration of course and tuition.
Am wondering how do I create the controller code for the school courses? Do I create a new controller file or use the existing controller file for the school profile? Does data being in separate database tables mean using separate controllers?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire