mercredi 6 novembre 2019

Laravel 6: trying to get property of non-object

Error: Trying to get property 'gender_id' of non-object

Controller:

public function printreports(Request $request)
{
$id = $request->get('select2'); //eg. id=1
$teachers = DB::table('teachers')->find($id);
return view('teachers.report1',compact('teachers'));
}

View:

@foreach($teachers as $teacher)

@endforeach

while if i do it with Eloquent by replacing following query it works, but i want to do it with DB query as stated above.

$teachers = Teacher::find($id);


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire