Laravel-Testing-Decoded icon indicating copy to clipboard operation
Laravel-Testing-Decoded copied to clipboard

Chapter 10 (page 134): View::make() problem

Open aschwin opened this issue 9 years ago • 1 comments

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!

aschwin avatar Jul 15 '15 14:07 aschwin

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'));
   });

jmarcher avatar May 07 '16 02:05 jmarcher