Trying to get property of non-object laravel 5 hasOne eloquent -
im trying use hasone relation following error : trying property of non-object (view: /home/vagrant/code/gsup_backend/resources/views/exam/index.blade.php) my models
class session extends model { /* * @var string * */ protected $table = 'gs_session'; protected $primarykey = 'idsess'; public $timestamps = false; public function exam(){ return $this->belongsto('app\model\exam','idex','idsess'); }}
the exam model
class exam extends model { /* * @var string */ protected $table = 'gs_exam'; public $timestamps = false; protected $primarykey = 'idex'; /* * @var string */ protected $fillable = ['*']; public function matiere(){ return $this->hasone('app\model\matiere','idmat','idex'); } public function session(){ return $this->hasone('app\model\session','idsess','idex'); } public function personne(){ return $this->hasone('app\model\personne','idper','idex'); }}
my controller action
public function index() { $exams = exam::all(); return view('exam.index',compact('exams')); }
my view
@foreach($exams $exam) <tr class="gradex"> <td>{{$exam->personne->prenomper}} {{$exam->personne->nomper}}</td> <td>{{$exam->matiere->libelleapomat}} </td> <td>{{$exam->session->libellesess}}</td> <td class="center">{{$exam->statut}}</td> <td class="center">{{$exam->date}}</td> <td class="center">{{$exam->heuredeb}}</td> <td class="center">{{$exam->heurefin}}</td> <td class="center"><span><button class="btn btn-primary">modifier</button></span> <span><button class="btn btn-danger">supprimer</button></span> </td> </tr> @endforeach
i think problem right here {{$exam->session->libellesess}}
ive solved problem usign :
@if($exam->session) {{$exam->session->libellesess}} @endif
Comments
Post a Comment