내 응용 프로그램에 등록하려고하는데이 오류가 발생했으며 이유를 모르겠습니다. laravel 5.4 이외의 객체 오류 속성을 얻으려고합니다.
내 post.blade.php 파일이 코드를 가지고 :
public function index()
{
$posts=Post::latest()->get();
return view('posts.index',compact('posts'));
}
및 인덱스 파일은 다음과 같습니다 :
<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이 코드를 가지고
@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