laravel中获取某模型所有结果并赋值到模板
public function index()
{
//
$post = Post::all();
return view('post.index',compact('post'));
}
模板写法:
@foreach ($post as $news)
<p>此用户为 {{ $news->title }}</p>
@endforeach
public function index()
{
//
$post = Post::all();
return view('post.index',compact('post'));
}
@foreach ($post as $news)
<p>此用户为 {{ $news->title }}</p>
@endforeach