Create a Laravel application:
$ composer create-project laravel/laravel hello-world
Navigate to the project folder, e.g.
$ cd C:\xampp\htdocs\hello-world
Create a controller:
$ php artisan make:controller HelloController --resource
This will create the file app/Http/Controllers/HelloController.php. The
--resource
option will generate CRUD methods for the controller, e.g. index, create, show, update.
index
method. Add this line to app/Http/routes.php (version 5.0 to 5.2) or routes/web.php (version 5.3): Route::get('hello', 'HelloController@index');
To see your newly added routes, you can run
$ php artisan route:list
Create a Blade template in the views
directory:
resources/views/hello.blade.php:
<h1>Hello world!</h1>
Now we tell index method to display the hello.blade.php template:
app/Http/Controllers/HelloController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class HelloController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('hello');
}
// ... other resources are listed below the index one above
You can serve your app using the following PHP Artisan Command: php artisan serve
; it will show you the address at which you can access your application (usually at http://localhost:8000 by default).
Alternatively, you may head over directly to the appropriate location in your browser; in case you are using a server like XAMPP (either: http://localhost/hello-world/public/hello should you have installed your Laravel instance, hello-world
, directly in your xampp/htdocs directory as in: having executed the step 1 of this Hello Word from your command line interface, pointing at your xampp/htdocs directory).