您好,我想获得我的答复表上的用户名,但它只显示我的用户id,当我键入$REPLY-&>USER_ID-&>NAME时,它显示错误:"try 读取属性"NAME"on int".
我怎么才能修好它呢?
以下是我的代码:
100
public function replies() {
return $this->hasMany(Reply::class);
}
100
public function tickets() {
return $this->belongsTo(Tickets::class);
}
100
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());
}
100
@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-&>名称.