Attempt to read property "doc" on null

I have a candidat, and document Models but when I use $candidat->document->doc I get Attempt to read property "doc" on null

Document Model :

 class Document extends Model
{
use HasFactory;
protected $table = 'documents';
protected $fillable = [
'id_candidat',
'doc',
'date_depot'];

public function candidat()
{
return $this->belongsTo(candidat::class, 'candidat_id');
}
}

Candidat Model :

  class candidat extends Model
{
use HasFactory;
protected $table = 'candidats';
protected $fillable = [
'nom',
'prenom',
'email',
'adresse',
'date_naissance',
'telephone',
'cin',
];

public function documents()
{
return $this->hasMany(document::class);
}

CandidatController

  public function show()
{
$candidat = candidat::all();
return view('candidat.liste', compact('candidat'));

}

candidat/liste:

  @foreach($candidat as $key => $data)
{....
#this provoked the error
}

Thanks in advance



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2VIna57
via IFTTT

تعليقات

المشاركات الشائعة من هذه المدونة

5 Free Black and White Social Media Icons Sets with CSS and HTML

How to Create Treeview with Bootstrap and jQuery

How to Change Apache and MySQL Port Number in XAMPP Localhost