mardi 28 mai 2019

How to call model in Controller request $request

i have query in my model, which i want to call in my controller(request $request). it's working fine when controller parameter is controller($id). but how to pass it in $request controller.

My teacher Model with Query:

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')
   ->select('teachers.*','religions.*','areas.*')
   ->where('teachers.id',$id)
   ->first();
  }

Controller which calls this model perfectly fine passing direct id:

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

Controller Where i want to call it:

    public function printreports(Request $request)
    {
    $teachers = $request->get('select2'); 
return view('teachers.report1',compact('teachers'));
    }

//Select 2 contains teacher ids where i want to run model query.



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2ECPZnA
via IFTTT

Aucun commentaire:

Enregistrer un commentaire