Change default "/" route to use "HomeController@showWelcome"
hello!
I spent about 2 hours trying to figure out why my default installation of Laravel wouldn't allow me to do render variables in to my view. I tried View::make("hello")->with("test", "some test value") and I tried View::make("hello", array("test" => "some test value")) with no luck. I constantly received "variable undefined" when trying to use the $test variable in my views.
It turns out the default route for "/" was calling View::make("hello") directly in a callback function, while I was modifying the showWelcome method in HomeController. Once I changed the "/" route to use the controller method, everything worked fine. But it took me a long time to figure this out. It would be good to have the default "/" route configured like this:
Route::get('/', "HomeController@showWelcome");
so that others don't run in to the same frustration.
https://github.com/laravel/laravel/blob/master/app/controllers/HomeController.php#L14
Checkout the Laravel docs. The first article listed in the TOC is Routing (outside of installation & configuration), who's first sentence talks about routes being defined in app/routes.php, who's first example is the example that's in a vanilla Laravel 4 app. The very docblock above the method you were editing also alludes to this.
I've had moments like that, where I spend ages trying to figure out something that's taken way too long. Laravel's beauty is in it's simplicity, and that begins with routing.
I think spending 2 hours figuring out that the route was declared in app/routes.php was just you maybe having what I call a "Ben" moment lol. Don't worry man, we all do it.
Long story short, I don't think the default route should be modified to enforce newcomers to use controllers.
Route::get('/', 'HomeController@index')->name('home');