你好,我想得到我的回复表上的用户名,但它只显示我的用户ID,当我键入$reply-〉user_id-〉name时,它向我显示错误:尝试读取int的属性"名称"。
我该怎么修呢?
这是我的密码
票证型号
public function replies() {
return $this->hasMany(Reply::class);
}
回复模型
public function tickets() {
return $this->belongsTo(Tickets::class);
}
票证管理员
public function show($id) {
$user = Auth::user();
$tickets = Tickets::with('companies')->get();
$ticketscomp = Companies::with('tickets')->get();
$severities = Severities::with('tickets')->get();
$users = User::with('tickets')->get();
//$replies = DB::table('replies')->where('ticket_id', $id)->get();
// $articles = Reply::where('user_id', $id)->with('User')->get();
$ticketspage = Tickets::with('severities')->with('companies')->with('user')->with('replies')->findOrFail($id);
return view('tickets.ticket', compact('ticketspage'))->
with(['tickets'=> $tickets])->
with(['ticketscomp'=>$ticketscomp])->
with(['severities'=>$severities])->
with(['ticketspage'=>$ticketspage])->
with(['replies'=>$replies]);
//dd($reply_author->toArray());
}
刀片
@foreach ($replies as $reply)
<div class="NjBSH">
<div id="AuthorAndDate-1">
<span class="author">{{ $reply->user_id->name }}</span>
<span class="date"><span style="color: rgb(32, 33, 36);">{{ $reply->created_at }}</span><br></span>
</div>
<div class="kmSodw">
<span>{{ $reply->text }}</span>
</div>
</div>
@endforeach
文本,创建于同时显示$reply-〉user_id,但不显示此$reply-〉user_id-〉名称。
1条答案
按热度按时间dsekswqp1#
以下是使用ELOQUENT的完整解决方案:
票证型号
回复模型
票务管理员:
"刀锋"