Introduction to Laravel

Date Posted: 6/30/2020 Tutorial

30
Back

First, What is Laravel?

Laravel is an open-source PHP web framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller architectural pattern and based on Symfony.

Reference: laravel.com

Prerequisite: Laravel 5.6

Two way to create laravel project:

  • Via Laravel Installer
  • Via Composer

Via Laravel Installer

First, download Laravel installer using Composer.

composer global require "laravel/installer"

Note: Make sure to place composer's system-wide vendor bin directory in your path so the laravel executable can be located by your system. This directory exists in different locations based on your operating system; however, some common locations include:

  • macOS: $HOME/.composer/vendor/bin
  • GNU / Linux Distributions: $HOME/.config/composer/vendor/bin

To create laravel project, copy this code and paste to terminal or command prompt (cmd).

laravel new blog

Via Composer

First, download Composer and install it.

To create laravel project, copy this code and paste to terminal or command prompt (cmd).

composer create-project --prefer-dist laravel/laravel website
  • composer is a command to call Composer.
  • create-project is a Composer command to create project.
  • --prefer-dist is to faster and download the unzip dependencies of a project.
  • laravel/laravel this is the directory or project will be created in composer create-project command.
  • website is the name of laravel project (you change or rename it).

Local Development Server

If you have PHP installed locally and you would like to use PHP's built-in development server to serve your application, you may use the serve Artisan command. This command will start a development server at http://localhost:8000 :

To run your laravel project, copy this code and paste to terminal or command prompt (cmd). Make sure the location you run this code inside your laravel project directory.

php artisan serve

Note: Everytime you want to see your project you need to run this code in terminal or cmd. Don't close it or else you don't see your laravel project in browser.

Take a Tour in Laravel project

I created a laravel project named "website". This is the laravel project directory.

/ website - directory
    / app 
    / bootstrap
    / config
    / database
    / public
    / resources
    / routes
    / storage 
    / tests 
    / vendor 
    .env 
    .env.example 
    .gitattributes 
    .gitignore
    artisan
    composer.json 
    composer.lock 
    package.json 
    phpunit.xml
    server.php 
    readme.md 
    webpack.mix.js
  • First, app directory have console, exceptions, http or controller, provider and models.
  • bootstrap directory, have cache and autoload.
  • config directory have app, auth, broadcasting, cache, database, filesystems, mail, queue, services, session and view configuration.
  • database directory have factories or database generator, migrations and database seeder.
  • public directory have css, js, .htaccess, index.php and web.config. In this directory you can store your fonts, images or any files you want to share in public.
  • resources directory have assets, validations and view. In this directory you can make your php or html document or view display in your website and you can add blade templating.
    (I will discuss Blade Templating in my future tutorial)
  • routes directory have api, channels, console and web routing. In this directory you can customize your url and this is the connector of view and controller.
  • storage directory have app, framework and logs.
  • tests directory this is for testing purposes.
  • In vendor directory have dependencies or whole packages of laravel.

(I will discuss every files in laravel project in my future tutorial and I will teach you what is the purpose of it or how to use it.)

Advertisement: