2
votes

I'm a beginner in Laravel

I have just installed Laravel to my local server using xampp in E drive instead of c. When i opened this url http://localhost/laravel/public/ its working fine. I have created hello controller but when trying to open this url: http://localhost/laravel/public/hello getting page not found error.

I tried all htacess methods but still not working. Please help me to access controller.

2
show your route and controller codePankaj Makwana
Can u pls share your routes and controller?Bits Please
Have you tried running php artisan serve on your command line?paudel
I have used this code in routes.php file. Route::get('/hello',function(){ return 'Hello World!'; });Nisha Sharma
The folder public should be your server's document root and not turn up in any url.brombeer

2 Answers

3
votes

Since you are using XAMPP, it will be better for you to register a new virtual host on your xampp's Apache. Just go to /path-to-xampp/apache/conf/extra/httpd-vhosts.conf

And add this code

<VirtualHost *:80>
    ServerName mylaravel-app.local
    DocumentRoot "e:/path-to-xampp/htdocs/laravel/public"
    <Directory  "e:/path-to-xampp/htdocs/laravel/public/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

After that, you save it and restart your XAMPP to refresh its DNS. Then you can now view your app on http://mylaravel-app.local

UPDATE for sample code:

// app\Http\Controllers\Hello.php
class Hello extends Controller {

    public function index() {
        echo "Hello world!";
    }

    ...
}

// routes:
Route::get('/hello', 'Hello@index');

// then you test it on http://mylaravel-app.local/hello
0
votes

You also need to start your laravel server. First go to your project root directory from CMD. Than run Command php artisan serve in cmd. so the laravel server is started. After this you not get error of page not found !