【发布时间】:2021-07-10 05:30:07
【问题描述】:
我正在使用 Laravel 8 开发我的在线论坛项目。
这是我到/uri的路线:
Route::get('/', function () {
$threads = App\Models\Thread::paginate(15);
return view('welcome', compact('threads'));
});
welcomeblade:
@section('content')
@include('thread.partials.thread-list')
@endsection
在thread-list,我添加了这个:
@forelse($threads as $thread)
Posted by <a href="{{route('user_profile',$thread->user->name)}}">{{$thread->user->name}}</a> {{$thread->created_at->diffForHumans()}}
@endforelse
但不知怎的,我得到了这个错误:
ErrorException 试图获取非对象的属性“名称”(查看:thread-list.blade.php)
那么这里出了什么问题?我该如何解决这个问题?
非常感谢你们的任何想法或建议......
提前致谢。
【问题讨论】:
-
您正在尝试从用户访问名称,但用户不只是线程表中的一个字段吗?比如id?
-
在您的问题中添加您的模型关系代码和数据库文件名。