后控制器
public function index()
{
$posts=Post::all();
return view('home')->with('posts', $posts);
}
网页.php
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::resource('posts','PostController');
家
@foreach($posts as $post)
<p>{{$post['content']}}</p>
@endforeach
我收到这个错误
Facade\Ignition\Exceptions\ViewException
Undefined variable: posts (View: C:\xampp\htdocs\lts\resources\views\home.blade.php)
$posts未定义
在刀片模板中使变量可选。替换{{ $posts }}为{{ $posts ?? '' }}
感谢大家的帮助,我可以通过添加来修复它
Route::get('/home', 'PostController@index');
我很想知道为什么这个问题是首先引起的,Route:: resource('posts','PostController');应该处理它。
慕村225694
阿波罗的战车
神不在的星期二
摇曳的蔷薇