Reputation: 11
The error that I am facing seems to be a common one. But the solutions I found on the various posts online, did not seem to solve my issue.
I am new to Laravel and have installed it on my local (WAMP) using a tutorial link.
The initial set-up seemed to work fine and my route (http://localhost/laravel/larashop/public/) page worked. However any other routes that I add to the routes.php or web.php file do not seem to work. I get an error saying NotFoundHttpException in RouteCollection.php line xyz.
My web.php file:
<?php
//works
Route::get('/', function () {
return view('welcome');
});
//does not work
Route::get('/hello',function(){
return "welcome";
});
//does not work
//Route::get('hello', 'Hello@index');
//does not work
/*Route::get('hello',function(){
return view('welcome');
});*/
I had used the php artisan make:controller Hello command to create the controller and added a simple index() function to it. But the links do not work even when I do not use the controller or the view (i.e. the return "welcome"
function).
I get the following to response to the php artisan route:list command:
c:\wamp64\www\Laravel\larashop>php artisan route:list
+--------+----------+----------+------+---------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+----------+------+---------+--------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | hello | | Closure | web |
+--------+----------+----------+------+---------+--------------+
Any helps would be appreciated. I am stuck!
Upvotes: 1
Views: 732
Reputation: 11
Using php artisan serve
, as suggested by Demonyowh and geckob, solves my problem! Thank you!
Upvotes: 0
Reputation: 8130
I think the way you setup the web server is not exactly correct. The web server should be pointing to public
folder. Then, you can just access it without the public
URI.
Using the information you provided, if you point it to the public folder, you can access these without the public
URL:
Route::get('/',function() { return 'Something'; })
http://localhost/laravel/larashop/
Route::get('/hello',function() { return 'Something'; })
http://localhost/laravel/larashop/hello
If you insist to point the web server to the root project folder which will include the public URI in the route(which highly not recommended), you can access your route as follows:
Route::get('/',function() { return 'Something'; })
http://localhost/laravel/larashop/public/
Route::get('/hello',function() { return 'Something'; })
http://localhost/laravel/larashop/public/hello
Upvotes: 0