0
我試圖使用hasOne關係,但我得到以下錯誤: 嘗試獲取非對象的屬性(查看:/ home/vagrant/Code/gsup_backend/resources /views/exam/index.blade.php) 我的模型試圖獲得非對象laravel屬性hasOne口才
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');
}}
考試模式
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');
}}
我的C ontroller行動
public function index()
{
$exams = Exam::all();
return view('exam.index',compact('exams'));
}
我看來
@foreach($exams as $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
我覺得問題就在這裏{{$exam->session->libellesess}}