Introduction to Laravel (Part 1)
This article will introduce you to one of the most popular and powerful web frameworks, Laravel.
Laravel is a powerful MVC PHP framework, designed for developers who need a simple and elegant toolkit to create full-featured web applications. Laravel was created by Taylor Otwell. This is a brief tutorial that explains the basics of Laravel framework
Laravel
Laravel is a PHP based web MVC framework with bundles, migrations, and an artisan command-line interface. Laravel provides a complete set of tools and an application architecture that offers many of the best features of frameworks like CodeIgniter, Yii, ASP.NET MVC, Ruby on Rails, Sinatra, and more.
Laravel is an Open Source framework. It has a very rich set of features which will boost the speed of Web Development. If you are familiar with Core PHP and Advanced PHP, Laravel will make your task easier. It will save a lot of time if you are planning to develop a website from scratch. Not only that, integrating security in a webapp made with Laravel is easy and straightforward and that is where it beats many other frameworks. It prevents the various attacks that can take place on websites.
Features of Laravel
Laravel offers the following key features:
- Contracts: They are basically a set of interfaces that defines the core services. If you need caching in package, you can achieve that using Illuminate\Contacts\cache. You can do cache programing anywhere in the code using the concrete cache class without changing the package code.
- Class auto loading: this means you do not have to manually load the classes.
- Route caching feature speeds up the application route registration. This feature is perfectly suitable for you if your application has a large number of APIs. You can use PHP artisan route: cache and PHP artisan route: clear commands to turn ON and OFF the route caching in the program. It is generally implemented as a part of the deployment process.
- Developers were forced to declare application events as a string until now. But you can declare new events in the application using “event object” using Laravel 5. You can create event objects using php artisan make:event <event-name> and event header object using php artisan handler:event <handler-name>.
- RESTful controllers – this allows you to take advantage of HTTP verbs such as GET, POST, PUT, and DELETE etc.
- Authentication is one of the most important parts of any web app and developers spent much time writing the authentication code. Laravel 5 contains the ready to use inbuilt authentication system. You just need to configure database migrations, models, controllers and views to make the system work.
- Method Injection has been significantly simplified in the latest version of Laravel. You had to demand Inversion of Control (IoC) container to provide a class instance until Laravel 4.2. But you can declare the type hinted class instance in the controller method's signature now.
- Unit Testing – built in unit testing features that can be run from the artisan command line.
- Support for composer Laravel uses composer. Composer is a package management system for PHP. This means you can use packages from www.packagist.com in your Laravel projects
- Eloquent ORM – Eloquent is an Object Relational Mapper framework that implements PHP Active Record.
Comparison of PHP Frameworks
While designing your application, it is smart to compare frameworks you want to use because a framework might not be a right choice due to the features it does NOT offer!
How to choose a PHP framework
Answering a few questions can help you choose a framework:
- What are the features and functionality of the framework? (Does it offer what I need?)
- What is the learning curve of the framework?
- How scalable is the framework?
- Is the framework actively developed and maintained by the core team?
- Does the framework provide long-term support (LTS support) ?
- Does the framework have strong community support?
Symfony, Laravel, and Yii
Before diving into technical details, let’s look at an overview of other contenders:
Symfony
Symfony is a collection of reusable PHP modules, enabling the developer to create highly scalable, performance-oriented apps. With 30 modules to choose from, the developer has the freedom to try and work in a RAD environment. Symfony APIs also enable easy integration with third-party applications, and it can be used with popular front-end frameworks, such as AngularJS and Angular 2.
Many popular projects, including Drupal and phpBB, also use a Symfony framework. In fact, Laravel, the most popular PHP framework, is built off of Symfony.
Laravel
Laravel, which is known as the "PHP framework for Web Artisans," offers an excellent community and wins as the most popular framework. (One of the leading Laravel developers on Livecoding.tv is Sfiskell.)
In May 2015, Laravel announced that version 5.1 will offer long-term support for two years. Version 5.2 rolled out in December 2015. Many hosting companies provide Laravel support and offer hosting solutions for Laravel applications. Check out the Built with Laravel site to see examples of great projects.
Yii
Created by Qiang Xue in 2008, Yii is a secure, fast, high-performance application/web-development framework. Yii utilizes the Composer dependency manager for PHP for handling different dependencies and installations (more on it later). Yii also is the fastest PHP framework, thanks to the lazy loading technique.
Another great feature of Yii is jQuery integration. The integration enables front-end developers to embrace the framework quickly, and it uses scaffolding to generate code. Similar to Symfony, Yii also utilizes components to enable rapid application development.
How they compare
All three frameworks are great for building Web 2.0 applications, but each framework serves a different purpose. Let's look at their features and how they stack up.
Templating engines
Templating engines minimize developer effort and provides better functionality in writing front-end code. Templating engines provide features such as automatic HTML escaping and filters, and fill the gap left by raw PHP.
Laravel Blade templating system
Unlike other templating systems, Blade lets you use PHP code in the views. Also, Blade has zero overhead to application performance because the blade view files are stored in .blade.php extension. All the code in the view files is converted into raw PHP during processing.
Yii Default templating system
Yii doesn't utilize any third party templating system by default, but that doesn't mean it lacks templating system support. The choice of the templating system depends on the development team. Twig and Smarty are recommended. Symfony uses Twig, so if you have used Symfony in the past, you might want to utilize Twig for your next Yii project.
There is no clear winner here. All three frameworks use templating engines for better front-end coding and maintenance. A small advantage to Yii is that the framework does not have a pre-defined templating system.
Framework differences
Every framework is created differently. Symfony works on reusable components and provides the best modularity. Symfony also utilizes the model and controller for developing a web application, which may look rusty for many new developers, but it works. Also, Symfony is a good example of the modular framework. You can use the 30 components provided by Symfony in your project in a modular fashion.
Yii uses an MVC framework. (Symfony does provide support for MVC, which is discussed in more detail in Is Symfony2 a MVC framework on the blog.sznapka.pl site.)
Symfony can be used for rapid development and complex projects. Even though there is a debate on which framework is better for complex projects, Symfony does showcase brilliant complexity handling compared to other frameworks. Yii also utilizes components, but is not as modular as Symfony. Laravel doesn't provide a modular approach as sharp as the other two frameworks.
If you are looking for a modular framework, go for Symfony. Otherwise, Laravel and Yii are both great choices.
Conclusion
In the battle of Symfony vs. Laravel vs. Yii, all three PHP frameworks are excellent options that provide a full-stack development environment for developers. For me, Laravel is a winner that is emerging as a star with no sign of stopping.
It is now up to you to decide which is best for you!
Recent Stories
Top DiscoverSDK Experts
Compare Products
Select up to three two products to compare by clicking on the compare icon () of each product.
{{compareToolModel.Error}}
{{CommentsModel.TotalCount}} Comments
Your Comment