我試圖在我的應用程序中註冊,但發生了此錯誤,我不知道爲什麼。 嘗試在laravel 5.4中獲取非對象錯誤的屬性
和我post.blade.php文件中有這樣的代碼:
<div class="blog-post">
<h2 class="blog-post-title">
<a href="/posts/{{$post->id}}">
{{$post->title}}
</a>
</h2>
<p class="blog-post-meta">
{{$post->user->name }}
{{$post->created_at->toFormattedDateString()}}
</p>
{{$post->body}}
PostController中有這樣的代碼:
public function index()
{
$posts=Post::latest()->get();
return view('posts.index',compact('posts'));
}
和索引文件是:
@foreach($posts as $post)
@include('posts.post')
@endforeach
<nav class="blog-pagination">
<a class="btn btn-outline-primary" href="#">Older</a>
<a class="btn btn-outline-secondary disabled" href="#">Newer</a>
</nav>
</div><!-- /.blog-main -->
您是否從控制器傳遞'$ post'? –
檢查您是否傳遞$ post變量。 –
您確定created_at實際上是發送$ post嗎? – Frenus