Hello world in Laravel

1. Introduction

In this article, we are starting to learn about Laravel. Laravel is one of the most famous PHP Framework as well as the most-starred PHP framework on GitHub. This article follows the Laravel 5.5 LTS version. Taylor Otwell develops Laravel with beautiful code and developer happiness in mind. It has a minimal learning curve when compared to other PHP frameworks. At this point of time, we assume that we know the basics of PHP if not, you might want to go through our free course – Learn PHP in 10 Days  first. So let’s get started.

2. About composer

The composer is an application-level package manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries. It uses a JSON file named package.json to control the application level dependencies.
Laravel uses composer as dependency manager. To install Composer, download it from https://getcomposer.org/

3. Installing PHP and git for local environment

We use the XAMPP package for a local development environment. You can download the latest version of XAMPP from the official website https://www.apachefriends.org/

We also need to install the git source control on our system. You can download and install the git from here – https://git-scm.com/

4. Getting Laravel and starting a local server

Once you have your local environment ready, open up a command prompt and execute the following command

composer create-project --prefer-dist laravel/laravel blog "5.5.*"

This command will copy Laravel from github.com to your current folder and will install all the related dependencies.

To start the local development server.

php artisan serve

The command above will start a local PHP development server on http://localhost:8000

5. Hello World! in Laravel

Using an editor, open the file routes/web.php

In this file, you will find this code.

Route::get('/', function () {
    return view('welcome');
});

This welcome view produces the Laravel “welcome” page, which we can see in a browser on http://localhost:8000.

We can change this code to something like

Route::get('/', function() {
    return 'Hello, World!';
});

Now, when we browse http://localhost:8000, we see the string Hello, World!

6. Summary

In this article, we started with the introduction of Laravel, had an overview of the composer and prepared our local environment for development. Then, we created a hello world project in Laravel. In the next articles, we will learn more about Laravel. Stay happy and updated by subscribing to our newsletter.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *