【发布时间】:2018-11-01 05:19:31
【问题描述】:
我正在尝试从表中获取一个属性,但它告诉我它不存在:
我的观点是:
@foreach ($weeklyTicketsclosed as $ticket)
@if($ticket->statut=='fermé')
<tr>
<td>{{ $ticket->societe}}</td>
<td>{{ $ticket->intervenant}}</td>
<td>{{ $ticket->assistance->level}}</td>
<td>{{ $ticket->message}}</td>
<td>{{ $ticket->urgence->niveau}}</td>
<td>{{ $ticket->statut}}</td>
<td>{{ $ticket->utilisateur->name}}</td>
<td>{{ $ticket-> created_at}}</td>
<td>{{ $ticket->gestions->observations}}</td>
</tr>
@endif
@endforeach
我的门票课程是:
class Tickets extends Model
{
protected $table="tickets";
protected $fillable=['message','utilisateur_id','urgence_id','societe','typeassistance','intervenant'];
public function urgence()
{
return $this->belongsTo(\App\Urgence::class);
}
public function gestions()
{
return $this->hasMany(\App\Gestion::class, 'utilisateur_id');
}
public function assistance()
{
return $this->belongsTo(\App\assistance::class, 'typeassistance', 'id');
}
我的 Gestion 课程是:
class Gestion extends Model
{
protected $table="gestions";
protected $fillable=['description','duree','ticket_id','utilisateur_id','observations'];
public function tickets(){
return $this->belongsTo(\App\Tickets::class);
}
}
控制台在ticket->gestions->observations 上返回一个不存在的错误。 我似乎找不到它的来源,Gestion 和 Tickets 类之间的关系与 Tickets 和 Urgence 或 Tickets 和 Assistance 之间的关系一样。
错误:此集合实例上不存在属性 [观察]。 (查看:C:\xampp\htdocs\rmstickets\resources\views\export\ticketsexcelferme.blade.php)
你能帮帮我吗?
提前致谢!
【问题讨论】:
标签: php mysql laravel class relationship