如何使用Laravel View Composer将此查询数据传递给所有视图。目前,我正在使用模型和控制器将其传递给一个视图。
class teacher extends Model
{
public static function teacher($id)
{
return DB::table('teachers')
->leftjoin('religions', 'teachers.religion_id', '=', 'religions.id')
->leftjoin('areas', 'teachers.area_id', '=', 'areas.id')
->leftjoin('nations', 'teachers.nation_id', '=', 'nations.id')
>select('teachers.*','religions.*','areas.*','nations.*')
->where('teachers.id',$id)
->first();
}
控制器:
public function show($id)
{
$teacher = Teacher::teacher($id);
return View('teachers.report1' ,compact('teacher'));
}