Laravel-Testing-Decoded
Laravel-Testing-Decoded copied to clipboard
Chapter 10 (page 134): View::make() problem
Hi, I encountered the problem with the View::make() syntax. I am using 5.1 of Laravel, but I solved it myself.
The problem is:
Route::get('posts', function()
{
$posts = Post::all();
return View::make('posts.index', ['posts', $posts]);
});
Should really be:
Route::get('posts', function()
{
$posts = Post::all();
return View::make('posts.index', ['posts' => $posts]); // <-- notice the arrow!
});
Otherwise, the view will not have the correct array. Hope this helps!
Yes or you can also use compact() and the code will be something like:
Route::get('posts', function()
{
$posts = Post::all();
return View::make('posts.index', compact('posts'));
});