Reputation: 761
I defined this named route in my routes.php,
Route::get('/', [
'as' => 'home',
'uses' => 'PagesController@home'
]);
then I have this in my PagesController.php
public function home() {
return 'Welcome home!';
}
My question is why http://localhost:8000/home produces this error?
NotFoundHttpException in RouteCollection.php line 161:
Upvotes: 0
Views: 135
Reputation: 1557
The route name
is home
so you can access it from a controller, or view using URL::route('home')
. But the actual address in the URL is localhost:8000/
Upvotes: 2
Reputation: 7303
You haven't created a route
for the url /home
. You only created the /
route.
To further explain your problem, you just named your route with home
. That means you can link to {{url()->route('home')}}
in your view to go to the URL /
which will be your home page. You can also access this route from any controller using url()->route('home')
.
If you want to access the page /home
, you need to create a route for this.
eg:
Route::get('/home', ['as'=>'NameUrRoute', 'uses'=>'PagesController@SamplePage']);
'as'=>'home'
just indicates the name for the route. Not the URI
.
Upvotes: 4