# A Simple Laravel Hello World

DevFeed: [A Simple Laravel Hello World](<https://devfeed.tech/articles/a-simple-laravel-hello-world-28186.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/laravel/2021/05/27/a-simple-laravel-hello-world.html>)

Author: Fuzzygroup

Published: 2021-05-27T13:02:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Laravel](<https://devfeed.tech/topics/laravel.md>), [mvc](<https://devfeed.tech/topics/mvc.md>), [Ruby on Rails](<https://devfeed.tech/topics/ruby-on-rails.md>)

Tags: [application](<https://devfeed.tech/tags/application.md>), [composer](<https://devfeed.tech/tags/composer.md>), [controller](<https://devfeed.tech/tags/controller.md>), [framework](<https://devfeed.tech/tags/framework.md>), [html](<https://devfeed.tech/tags/html.md>), [index](<https://devfeed.tech/tags/index.md>), [laravel](<https://devfeed.tech/tags/laravel.md>), [models](<https://devfeed.tech/tags/models.md>), [php](<https://devfeed.tech/tags/php.md>), [route](<https://devfeed.tech/tags/route.md>), [simple](<https://devfeed.tech/tags/simple.md>), [test](<https://devfeed.tech/tags/test.md>), [text](<https://devfeed.tech/tags/text.md>), [variable](<https://devfeed.tech/tags/variable.md>), [view](<https://devfeed.tech/tags/view.md>), [world](<https://devfeed.tech/tags/world.md>)

## AI overview

The excerpt shows a minimal Laravel Hello World app built as a full application with one controller, one route, and a Blade view, without models or database connectivity. Create the project with Composer, generate `HelloController` using Artisan, and define its `index` method to return `hello_index`. Add a GET `/hello` route pointing to the controller action; the author says to use the fully namespaced controller path because importing it in the routes file did not work for them. Set `$text` in the action and pass it to the view as `['text' => $text]`, then create `resources/views/hello_index.blade.php`. Run `php artisan serve` and visit `http://localhost:8000/hello`. The excerpt's displayed view snippet is `<h1></h1>`, so it does not show the interpolation needed to render the passed text; the claimed "Hello World" display is not fully demonstrated in the supplied code.

## Source excerpt

As of late I've been working in Laravel and figuring out how Laravel differs from Rails. And while I have a bigger blog post in the works, I thought there was learning value in a simple Hello World implemented in Laravel. Hello World is a simple program that just puts Hello World on the screen. Here's how I thought a Laravel version of this should work: Be a whole Laravel application Be a single controller Be a single route Define the text "Hello World" as a variable, $text, in the controller Display that on the screen via an HTML template While this doesn't illustrated models and database connectivity, this actually illustrates how to use a surprising amount of an overall MVC framework. Step 1: Creating an Application The first step is to use composer to generate the overall application with: composer create-project laravel/laravel hello_world The next step is to change into the directory with: cd hello_world and then open the code base with: mate . or if you use Sublime: subl . Step 2: Generating a Controller Back at your command line, you want to generate a controller with: php artisan make:controller HelloController This will create a file named HelloController in app/http/Controllers: ls -l app/Http/Controllers total 16 -rw-r--r-- 1 sjohnson staff 361 May 18 11:37 Controller.php -rw-r--r-- 1 sjohnson staff 122 May 27 09:12 HelloController.php Inside the controller you want to add the following code (some of which will already be there from the generator): public function index() { return view('hello_index'); } inside the "class HelloController extends Controller" block of code (it goes inside the {} braces). Step 3: Adding a Route Moving back to the code base, you want to edit the file routes/web.php and add this line: Route::get('/hello', 'App\Http\Controllers\HelloController@index'); This adds a single route, /hello, which is then handled by the Hello controller and the hello_index action. You can test that this route is available by running: php artisan rout