Building with Laravel

  • Filter
  • Time
  • Show
Clear All
new posts

    Building with Laravel

    Click image for larger version

Name:	laravel.png
Views:	1
Size:	52.2 KB
ID:	113062

    Table of Contents

    1. Introduction
    2. What is a PHP framework?
    3. What is Laravel and why should I use it?
    4. Setting up your PHP environment
    5. Installing Laravel
    6. Hello world with Laravel
    7. ...more as time goes on.

    1. Introduction

    This is going to be a series of tutorials that will gradually unfold and hopefully at the end (depending on the response) you will all see the benefits of using Laravel, an awesome PHP framework.

    In this tutorial, I will assume everyone reading this has a fair knowledge of PHP and can comfortably write PHP scripts. So lets get started. If yoyu haven't already, set up your local web server. Download a copy of Laravel from their website.

    If you have done set up your web server on localhost and have a compressed zip of the Laravel framework, lets start. Please note that the tutorials will be strongly based on L3 (Laravel v3.x) so please make sure you have the right version.

    2. What is a PHP Framework

    Lets take a quick detour here and quickly define what a PHP framework is. A PHP framework is essentially a collection of PHP classes and libraries, coupled together to make application development faster and smoother.

    In layman's words, PHP frameworks speed up development time because it has classes and functions that help you do tasks quicker and safer. Take for instance, some Frameworks come shipped with a database class that essentially makes fetching data from databases easier and faster, makes table-to-table relationships easier to achieve. There are also caching classes, authentication classes, request classes, inbuilt clean URL structures etc. things tat you would have taken a lot of time to code from scratch.

    If you want to know more about php frameworks, i'd suggest you dig deeper.

    3. What is Laravel and why should i use it?

    According to their website: "Laravel is a clean and classy framework for PHP web development. Freeing you from spaghetti code, Laravel helps you create wonderful applications using simple, expressive syntax. Development should be a creative experience that you enjoy, not something that is painful. Enjoy the fresh air."

    The reasons you should use Laravel is the same reason why anyone will want to use a PHP framework in the first place: quick and safe development. Laravel provides an easy to use layer of libraries that just takes the pain away from developing apps. Literally in my first three days of learning Laravel, i had already started developing web apps.

    Laravel is very expressive, Just by reading the source code you can understand everything the code is trying to do. Take for instance this block of code from the frameworks core, i have stripped the comments out of it, now see if you understand this code without the commenting:

    PHP Code:
    class Str {

        protected static function 
            return static::
    $encoding ?: static::$encoding Config::get('application.encoding');

        public static function 
            return (
    MB_STRING) ? mb_strtoupper($value, static::encoding()) : strtoupper($value);

    Im sure its pretty obvious that calling Str::upper('hello') in our application will result in uppercase letters. Now you might ask, why use this instead of PHP's default strtoupper function? Well for one it looks cooler, and more importantly, it has support for multi-byte encoded strings.

    Every of Laravel's classes that seem to have normal php functions e.g session, cookies etc have added benefits. For instance, the Session class that comes with Laravel allows you easily store sessions on databases, also other session storage methods. The cookies class implements secure hashing to prevent some unnecessary holes in your application. So, bottom line, if Laravel has a class for it, use it.
    Last edited by CreativityKills; 17.04.13, 06:33.

    4. Setting Up Your PHP environment

    If you haven't already set up a development server, then I advise you to do so. Apache is a good place to start, so maybe you should start by Googling how to install a server locally, but as per the assumption I made at the beginning of this tutorial, its assumed you already have working knowledge of PHP and have a running server, I also mentioned that you download a working copy of the Laravel framework (v3.x). If you cannot find the v3.x listed on the site, then maybe you should look at their repository.

    Requirements for running Laravel
    • Apache, nginx, or another compatible web server.
    • Laravel takes advantage of the powerful features that have become available in PHP 5.3. Consequently, PHP 5.3 is a requirement.
    • Laravel uses the FileInfo library to detect files' mime-types. This is included by default with PHP 5.3. However, Windows users may need to add a line to their php.ini file before the Fileinfo module is enabled. For more information check out the installation / configuration details on
    • Laravel uses the Mcrypt library for encryption and hash generation. Mcrypt typically comes pre-installed. If you can't find Mcrypt in the output of phpinfo() then check the vendor site of your LAMP installation or check out the installation / configuration details on

    5. Installation

    • Download Laravel
    • Extract the Laravel archive and upload the contents to your web server.
    • Set the value of the key option in the config/application.php file to a random, 32 character string.
    • Verify that the storage directory and its sub-directories are writable.
    • Navigate to your application in a web browser.

    If all is well, you should see a pretty Laravel splash page. To see the docs, navigate to http://localhost/yourapp/public/docs/
    Last edited by CreativityKills; 17.04.13, 06:40.


      i did try laravel a couple of weeks ago, what annoyed me is that it doesn't have index file, if you place the content into web root and you open it you get directory listing..
      there is one in the /public directory but when you access it you get a blank page lol

      version is 3.2.13