mercredi 8 mai 2019

Laravel 5.8 : Passing Data to all Views using view Composer

How can i pass this query data to all views using laravel view composer. currently i am doing it using model and controller to pass it to one view.

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();
  }

Controller:

public function show($id)
{
$teacher = Teacher::teacher($id);
return View('teachers.report1' ,compact('teacher'));
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire