Monday, 8 December 2014

Introduction to Laravel Framework

Introduction to Laravel Framework

This book is about Laravel, a web application development framework that saves you time and effort and makes web development a joy. Laravel has shaken up the PHP community in a big way - especially when you consider that version 1.0 of Laravel was only a couple of years ago. It has been generating a lot of buzz with the promise of making web applications fast and simple to create. Using Laravel, you can build and maintain high-quality web applications with minimal fuss.
Certain parts of a web application development process can be a repetitive, boring task. Laravel lets you focus on the fun stuff - the crux of your web app - while easing the pain of the repetitive bits. In doing so, it provides high-level abstractions of common web development patterns, convenient shortcuts for frequent programming tasks, and clear conventions for how to solve problems.

Architecture of Laravel Applications

Laravel is referred to as a “full stack” framework because it handles everything from web serving to database management right down to HTML generation. A vertically integrated web development environment can provide a better experience for the developer.
The typical developer interacts with Laravel through a command-line utility that generates and manages the Laravel project environment. Laravel comes with an excellent command-line tool named Artisan that can be used to generate skeleton code and database schema stubs. Artisan handles everything from database schema migration to asset and configuration management.

Convention Over Configuration

One of the interesting features of Laravel is that it imposes some fairly serious constraints on how you structure your web applications. Surprisingly, these constraints make it easier to create applications - a lot easier. Let’s see why.
Laravel differs from other vertically integrated environments in its strong preference for convention over configuration. Whereas some Java, Python or PHP frameworks often require lots of XML configuration, Laravel requires almost none (or perhaps only a few lines of PHP) to get started. This aversion to configuration files makes for a very distinctive and recognizable code structure that is the same across all Laravel apps.

One Project Structure To Rule Them All!

It comes as no surprise that all Laravel projects have essentially the same directory structure - one in which every file has its designated place. By gently forcing this directory structure upon developers, Laravel ensures that your work is semi-automatically organized the “Laravel way”.
Figure 1.1 shows what the Laravel project directory structure looks like:
As you can see, this standard directory structure consists of quite a few subdirectories. This wealth of subdirectories can be overwhelming at first, but we’ll explore them one by one. Most of your work will happen in the app/ folder, but here’s a basic rundown on the function of each of the files and folders:
Top-level FoldersPurpose
/app/Contains the controllers, models, views and assets for your application. This is where the majority of the code for your application will live. You will be spending most of your time in this folder!
/public/The only folder seen to the world as-is. This is the directory that you have to point your web server to. It contains the bootstrap file index.php which jump-starts the Laravel framework core. The public directory can also be used to hold any publicly accessible static assets such as CSS, Javascript files, images and other files.
/vendor/A place for all third-party code. In a typical Laravel application, this includes the Laravel source code and its dependencies, and plugins containing additional prepackaged functionality.
As mentioned above, /app is where all the fun happens, so let’s have a deeper look at the structure of this directory.
Figure 1.2 shows the /app folder in detail:
File/FolderPurpose
/app/config/Configure your application’s runtime rules, database, session and more. Contains a number of config files for changing various aspects of the framework. Most of the config files return associative PHP arrays of options.
/app/config/app.phpConfiguration for various application level settings, i.e. timezone, locale, debug mode and unique encryption key.
/app/config/auth.phpConfiguration that controls how user authentication will be performed in the application, i.e. authentication driver
/app/config/cache.phpIf the application utilizes caching to speed up response time, this is where you configure the feature.
/app/config/database.phpContains relevant configuration information for the database, i.e. default database engine and connection information.
/app/config/mail.phpConfiguration for e-mail sender engine, i.e. SMTP server, From: header
/app/config/session.phpConfiguration that controls how user sessions are managed by Laravel, i.e. session driver, session lifetime.
/app/config/view.phpMisc. configuration settings for templating systems.
/app/controllersContains the controller classes that are used to provide basic logic, interact with data models, and load view files for your application.
/app/database/migrations/The migrations folder contains PHP classes which allow Laravel to update the Schema of your current database while keeping all versions of the database in sync. Migration files are generated using the Artisan tool.
/app/database/seeds/The seeds folder contains PHP files which allow Artisan to populate database tables with reference data.
/app/lang/PHP files containing arrays of strings to enable easy localization of the application. By default the directory contains language lines for pagination and form validation for the English language.
/app/models/Models are classes that represent the information (data) of the application and the rules to manipulate that data. In most cases, each table in your database will correspond to one model in your application. The bulk of your application’s business logic will be concentrated in the models.
/app/start/Contains custom settings related to the artisan tool as well as global and local context.
/app/storage/The storage directory is used as temporary file store for various Laravel services such as sessions, cache, compiled view templates. This directory must be writable by the web server. This directory is maintained by Laravel and you need not tinker with it.
/app/tests/The tests folder provides a convenient location for you to keep your application Unit tests. If you are using PHPUnit, you can execute all tests at once using the Laravel Artisan tool.
/app/views/The views directory contains your HTML template files used by controllers or routes. Note that you should place only the view template files in this location. Other static assests such as stylesheet, javascript and image files should be placed in the /public folder instead.
/app/routes.phpThis is your application’s routing file which holds routing rules that tells Laravel how to connect incoming requests to route handler closure functions, controllers and actions. This file also contains declarations for several events including error pages, and can be used to define view composers.
/app/filters.phpThis file contains various application & route filter methods that alter the outcome of your application. Laravel has some pre-defined filters for access control and XSS protection.
A lot of thought has gone into establishing and naming the folders, and the result is an application with a well structured file system.


4 comments:

  1. Thanks for sharing the useful blog about working with Laravel framework.

    Web App Development Company in Coimbatore

    ReplyDelete
  2. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    php internships in hyderabad
    best php development companies in hyderabad

    ReplyDelete
  3. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.Keep it up. PHP Services
    Ecommerce service provider
    Data Extraction Services Company
    Big data development company in Chennai

    ReplyDelete
  4. The great information that you shared. It will help all of them. Thanks for posting. Keep maintain the updates
    PHP web development services|
    ERP Software|
    Ecommerce website builder|

    ReplyDelete

Simple CRUD in Laravel Framework

Creating, reading, updating, and deleting resources is used in pretty much every application. Laravel helps make the process easy using reso...