Monthly Archives

January 2017

Getting Started – Hello World! in Laravel 5.3

By | Laravel

To get started with basic page running in Laravel, we will open file called web.php which is inside routes folder (i.e.  inside ‘laravel_project_folder/routes/web.php’). Delete existing content in the file and add following code to get started with.

By using the above code, whenever a get request  for base directory is passed to the server, it will return “Hello World!” as an output. To see output we need to get back to terminal and pass the following command in the directory where the Laravel project is present.

php artisan serve

It will display that “Laravel development server started on”

So open in your browser and you will see Hello World! page generated by Laravel :)

Laravel 5.3 Understanding File and Directory Structure

By | Laravel

Laravel follows the model–view–controller (MVC) architectural pattern. Hence the directory structure can be confusing for a person who is not much seen into MVCs. But It is very easy to understand.

I’ll cover the basic directories which are mostly used. If anything you don’t understand, I’d suggest to progress further, it will get clear by developing on the platform. So Let Get started with Directory Structure.

There are many files in your root of Application director. Some important one are:

artisan: It is end point for artisan command which is used for various tasks and function in Laravel.

composer.json: Dependency and all list for composer installation

.env: This file contain configuration based on the environment of the application.

package.json: This file contain node related dependency, for example compiling SASS or LESS.

Upon installing following directories will be created

  • app
  • bootstrap
  • config
  • database
  • public
  • resources
  • routes
  • storage
  • tests
  • vendor

The app Directory

This directory contain core files of the application.  it is further divided in following sub directory:

  • Console: This contain custom artisan commands for the application
  • Exception: This directory contain application exception handler.
  • Http: This directory contain controllers & middleware. They are placed in their respective directories.
  • Providers: This directory contains service provider for your application. For example by default Laravel comes with Authentication provider which when enabled, is used for authentication purposes.

The config Directory

As you have gussed by the name of the directory, it contains all of your application’s configuration files.

The database Directory

This directory contain database migration and seeds. If you don’t know what is database migration and seeds, don’t worry it will be covered in upcoming posts.

The public Directory

This is the main directory where entry point index. php file is place. While running from server, this should be the point from where the application can be called on. Alternatively, images, JS and CSS are fetched from this directory

The resources Directory

This directory contains raw, uncompiled assets such as LESS, SASS or JS. It also contain template and language files for the application.

The routes Directory

This directory contain the route files, i.e. something like pretty URL for your application and its corresponding views. It will get more clear in upcoming posts.


The storage Directory

It contains compiled templates, caches and logs file.

The test Directory

It contain automated test for your php application. PHPUnit is provided out of the box.

The vendor Directory

It contain various supporting frameworks, codes and dependencies to make application working.

Laravel 5.3 Installation

By | Laravel

Laravel need following perquisites to get working:

  • PHP >= 5.6.4
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

I will be using PHP 7.0 along with mysql for my database requirement.

There may be different way to install Laravel project, but as per official documentation, it utilize Composer to manage its dependencies. To install Composer one can follow instructions at their official website which can be found here.

After installing composer, we will install Laravel globally. Installing Laravel globally helps to utilize Laravel command anywhere. To install ‘laravel’ as command, pass the following command in your terminal.

composer global require "laravel/installer"

The screen will show where the laravel files are getting installed. Note down that path. In my case the files got stored on ~/.config/composer/

For enabling ‘laravel’ command, we will add the following line in shell config file. Since I use Bash Shell, the config file will be located at ~/.bashrc

export PATH "~/.config/composer/vendor/bin:$PATH"

Close and run shell again to see ‘laravel’ command. Pass ‘laravel’ command in your shell. If everything is working fine, you will be greeted with laravel installer showing Laravel installer version, options and available commands.

Next navigate to your desired folder where you want to install your new Laravel project, and pass the following command.

laravel new project_name

As you have guessed, you can replace project_name with anything. The above command will install Laravel into the project_name directory and might take a while depending on your internet connection speed.