This is my model code:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Courses extends Model
{
protected $table = 'courses';
foreach ($courses as $course) {
echo $course->course;
}
}
I have no idea if the above code is the correct way to do it but the table is called courses.
Here is the code snippet I want to edit. Many people have said the code looks weird but it works. Please don't critique it....I just need to figure out how to insert the courses variable into it.
//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.
So the code that needs to be inserted might look like something like this:
$courses = Courses::where('[not sure what to put here]', '=', $[not sure what to put here])->first();
Then in the with array at the bottom: 'courses' => $courses,
Each course is assigned the ID of the school it matches to. So in the schools table, if schoolA has the ID of 5, then all the courses for schoolA in the courses table will also have 5 as the school_ID.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire