Laravel: An Artisanal PHP Experience

Laravel: An Artisanal PHP Experience
4026 views
0 comments

About a quarter century ago, at the dawn of the Internet, PHP was introduced to the early online world by Rasmus Lerdorf. Frameworks were released to expand on PHP’s functionality. Today, there is a PHP web development framework, Laravel, which after nearly a decade in existence, has become very popular for website and application building.

First a mini-history about PHP’s origin. According to PHP.net’s history page:

Created in 1994 by Rasmus Lerdorf, the very first incarnation of PHP was a simple set of Common Gateway Interface (CGI) binaries written in the C programming language.

Originally used for tracking visits to his online resume, he named the suite of scripts “Personal Home Page Tools,” more frequently referenced as “PHP Tools.” Over time, more functionality was desired, and Rasmus rewrote PHP Tools…

This new model was capable of database interaction and more, providing a framework upon which users could develop simple dynamic web applications such as guestbooks.

In June of 1995, Rasmus
released the source code … to the public, which allowed developers to use it as they saw fit. This also permitted – and encouraged – users to provide fixes for bugs in the code, and to generally improve upon it.

Over the years since PHP’s release, websites became more complicated.

PHP was an untamed code for developers:

PHP had been like the wild west of programming languages. Because it is dynamically typed, there are a lot of things that could potentially go wrong with no warning. For example, in other languages, code is written in such a way that if a mistake is made it can be caught before code execution. Either by trying to use the code or by compiling it, the compiler would actually stop you, identify the problem in the code, and require you to fix it before moving forward.

Out of the box, PHP has none of that. So theoretically you can continue writing poor code without knowing whether or not it works, forever. When something does go wrong, you have to spend a lot of time hunting for the problem.

One of the first big websites built with PHP was Yahoo. Facebook was built with an in-house version of PHP, “Hip Hop Virtual Machine”. One of the top reference sources for this blog and this post is Wikipedia – which was built with PHP. This very blog was built on WordPress which uses PHP and MySQL. With the explosion in the Internet, there was room for both improvement and for making web developers’ lives easier.

Frameworks emerged for making web development easier, including – the rise of a very popular PHP framework – Laravel.

Laravel is an open-source PHP framework designed to make developing web apps easier and faster through built-in features. Relatively new but with rich documentation, it has become one of the most popular PHP frameworks with developers.

The Laravel site describes itself as ““The Web Framework for PHP Artisans”:

The framework “attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as authentication, routing, sessions, and caching… Laravel aims to make the development process a pleasing one for the developer without sacrificing application functionality.

Laravel was introduced in 2011 by Taylor Otwell, a developer with a Microsoft “.net” perspective, to make web application development easier with an alternative to a pre-existing PHP framework, CodeIgniter. CodeIgniter was the most popular PHP framework thanks to its documentation but it had shortcomings which Otwell wanted to address with Laravel.

The philosophy of Laravel is worth a read:

Laravel’s Philosophy

Laravel’s popularity, a framework based on Symfony with its simplicity and syntax (e.g. “syntactic sugar” – simple and clean syntax), for back-end web developers was thanks to tools built into the framework. There were libraries and native commands making it easier to create web applications faster. It included basic features of PHP frameworks (and languages) including CodeIgniter (and Ruby on Rails).

Laravel’s motto was “developer happiness from download to deploy”.

Built-in features are an important reason for Laravel’s popularity, including:

The very feature which the older PHP framework CodeIgniter did not have: Simple authentication and authorization techniques. Laravel makes performing authentication and authorization techniques simple – thanks to its configuration. These techniques control how a server recognizes, i.e. authenticates, clients and allows, i.e. authorizes, clients permissions to use resources and files.

Other features of Laravel include:

Composer”, released as part of a Laravel updated release in 2013 which allowed developers to install prepackaged / routinely used code ready for deployment. This meant modular packaging with dependency management. (a/k/a functionalities could be added to a Laravel-based application easily).

“Composer” enabled collaboration between developers. Before this feature, you couldn’t simply take two different packages and mash together different parts from each to build something new. This was a catalyst in accelerating Laravel’s popularity and encouraged collaboration.

Artisan”: Laravel’s own command-line interface (CLI) with many pre-built commands, which enabled developers to automate many repetitive and complex tasks.

An “Automatic Package Discovery” feature means packages users want to install are detected automatically.

Automatic Testing is another essential and valuable feature.

Homestead”: a portable, virtual development environment.

Blade” templating engine: intuitive feature helping developers deal with “spaghetti” PHP / HTML.

Laravel’s Object-relational mapping (“ORM”) for easier data access and manipulation is very popular because it has object oriented libraries not found in other PHP frameworks. This includes a pre-installed library for authentication (with valuable features including password reset, protection, encryption, and Bcrypt hashing).

Laravel’s authentication library also assures security – passwords aren’t saved as the plain text in the database because they are hashed. Prepared SQL statements are used, preventing injection attacks.

Laravel’s Responsable Interface is a recent feature – it’s a class which is used to implement the interface which can be returned by using the controller (of MVC) method.

Laravel’s database migrations – likened to database version control – enables developers to change, update and share the application’s database schema. This is a very valuable feature – to easily make changes (e.g. add a row or a column to database schema) and to easily migrate to different development environments.

Laravel’s community of developers are supported by educational “Laracasts” tutorials.

A core feature of Laravel? It uses a simple controller-type of interface, “model-view-controller (MVC)” – introduced in its second version. 

MVC means an architectural pattern which breaks an application into three basic parts: a “Model” (the data), a “view”, an interface to see and change the data, and a “controller” which are the operations that can be performed on that data.

A tasty analogy, with the help of the DEV.TO website to explain MVC:
You order a pizza. That’s a user “call”. Your order, your request, is registered.

The “Controller”, the chef, breaks the order down into a sequence for making a pizza.

The “Model” includes labor, the ingredients, an oven, the pizza pan, heating fuel, etc.

The “View” is a hot delicious pizza received by the user.

A few considerations for Laravel users to consider:

IF YOU KNOW PHP you can learn Laravel. You can use it to build a site that is feature rich and secure from attack with less work.

IF you DON’T KNOW PHP, you can use Laravel sort of – but not fully. You’ll be limited to what’s inside Laravel’s framework.

PHP is the MOTOR under the “hood” of Laravel’s framework. Working on the code “under the hood” would directly improve the performance of a web application. Laravel as a “back-end”, i.e. server-side, framework means that developers can build applications rich with features including user accounts, transactions, and more. Its power is its simplicity and developer friendly and supportive philosophy, resources and community.

If you’re someone with a PHP background you likely already use Laravel or you will eventually. If you were curious and needed to know more about as an end user of an application or site, feel free to reach out to us.

Recent Posts