简体   繁体   中英

Laravel showing blank page

I just setup a Laravel 5 framework in my server by typing in terminal

laravel new blog (in "/var/www/html/" folder),

then changed the default config of Nginx so the root pointing to : root /var/www/html/blog/public;

of-course all the files are in place however I currently just see a blank page showing up ! I tried to put a html & PHP file in public folder and it all works fine. but not Laravel default index file. what am I missing here ?

For adding pages in Laravel you do not simply put files in /public . Please have a look at the official Laravel page if you want to create new views.

Laravel uses the MVC principle. So you need to have at least a view (the part which is displayed) and a controller which handles the view. To add a new Controller , please change to the project root cd /var/www/html/blog and type in php artisan controller:make AwesomeController which creates the controller in app/Http/Controllers/AwesomeController.php .

In this Controller you can simply return a view by adding return view('myview') to the index() Method for example. (The view has to exist at resources/views/myview.blade.php of course)

In the last step you need to tell Laravel how to call your controller. Please modify the routes.php file at app/Http/routes.php and add Route::get('foo', 'AwesomeController'); . Now you need to tell composer that some of your controllers may have changed and composer needs to refresh the cache. Type in composer dump-autoload and start the development server php artisan serve .

By calling http://localhost:8000/foo (by default) you should see your View. Have a nice day!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM