我不打算用laravel中的foreach打印所有论坛。我试图编写代码:
Route::get('', function()
{
return View::make('home', array(
$forums = DB::table('select * from forums')
));
});
然后在模板中编写foreach:
@foreach ($forums as $forum)
<p>This is forum {{ $forum->name }}</p><br>
@endforeach
但它没有用,它打印出来:
未定义的变量:论坛(查看:C:\ myadmin \ htdocs \ resources \ views \ home.blade.php)
提前致谢!
答案 0 :(得分:3)
正确执行以下操作的方法如下:
Route::get('', function()
{
return View::make('home', array(
$forums = DB::table('forums')->select()->get()
));
});