Reputation: 868
I create a fresh laravel 5 project and the routes file is as bellow.
Route::get('/', function () {
return view('welcome');
});
When I access it with http://localhost/mysite/laravel/public/ it works fine and goes to the welcome page. But when I modify the route as bellow and access it as http://localhost/mysite/laravel/public/blogs an error occurs.
Route::get('/blogs', function () {
return view('welcome');
});
Error:
NotFoundHttpException in RouteCollection.php line 161:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 821
at Router->findRoute(object(Request)) in Router.php line 691
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 54
The project is a fresh one and I didn't change any file except the route. What is the reason for this error? I am using laravel 5.x and XAMPP. I read all the similar questions in stackoverflow but still I couldn't find an answer please help.
Upvotes: 0
Views: 710
Reputation: 335
You can also run the laravel project by opening up command prompt, change the working directory into the laravel project folder, and fire the command "php artisan serve".
Your laravel project can now be accessed via - localhost:8000.
The reason why you cant directly from the xampp without virtualhost configuration is that the laravel app uses the public folder as the 'root', for security reasons, unless you append /public into the accessing URL.
Upvotes: 2
Reputation: 1319
You must setup virtualHost;
# VirtualHost for LARAVEL.DEV
<VirtualHost laravel.dev:80>
DocumentRoot "C:\xampp\htdocs\laravel\public"
ServerAdmin laravel.dev
<Directory "C:\xampp\htdocs\laravel">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
and add etnry to hosts
file located in:
C:\Windows\System32\drivers\etc
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 laravel.dev
Just remember to adjust paths.
Upvotes: 2