In the early days of dynamic Web development, writing a Web application looked very different than it does today. Developers are not only responsible for writing business logic for our application, but also for writing common components for the entire application or website, such as user authentication, input validation, database access, templates, and so on.
Today, developers have a plethora of application development frameworks, thousands of components, and easily accessible class libraries. Programmers often talk about the fact that by the time you finish learning a framework, several new (and supposedly good) frameworks are already out there, and tend to replace them.
“Just because it’s there” may be a valid reason to climb a mountain, but there are better reasons to choose a particular frame or to use one entirely.
Here’s a question worth asking:
Why choose a framework? More specifically, why Laravel?
Why use a framework
It’s easy to see why using separate components or packages is beneficial. For these packages, someone else is responsible for developing and maintaining the clearly defined separate code. In theory that person has time to understand the individual component more deeply.
Frameworks such as Laravel, Symfony, Silex, Lumen, and Slim are all made from pre-assembled third-party components such as configuration files, service providers, directory structures, and application startup in different ways. So the overall benefit of using a framework is that someone has already made a single component for us and provided us with the means to use it.
Diy
Let’s talk about creating a New Web application without the benefits of a framework.
First of all, where do you start? Well, you probably need an HTTP request route first, so you need to research all the available HTTP request and response libraries and choose one. Once the route is selected, you may also need to set up some form of routing profile. What syntax should it use? Where should it go? What about the controller? Where do they go? How is it loaded? You may need a dependency injection container to handle controllers and their dependencies. But which one?
Also, if you take the time to solve all the problems and build a successful app, what impact does that have on the next developer? What if you have three of these custom framework applications, or more? You have to remember where each application’s controller is, right? Or what is the routing syntax? And so on.
Consistency and flexibility
Which component should we use here? The framework actually provides a thoughtful answer to this question. And the framework ensures that the selected components work well together. In addition, the framework provides specifications that allow us to reduce new people’s understanding of the amount of code on a project. If you understand how pathways work in one Laravel project, then you understand how pathways work in all Laravel projects.
A brief history of Web and PHP frameworks
Maybe an important part of answering the question “Why Laravel” is understanding the history of Laravel, understanding what happened before. In fact, before Laravel became popular, there were many frameworks in the PHP language, as there were in other Web development languages.
Ruby on Rails
David Heinemeier Hansson released the first version of Ruby on Rails in 2004, and it was also hard to find a Web application development framework back then, which was somewhat unaffected by Raisl.
Rails promotes MVC, RESTful JSON apis, convention over configuration, ActiveRecord, and many other tools and conventions that have had a profound impact on the way Web developers approach their applications, especially in the area of rapid application development.
The influx of frameworks
It was clear to most developers that Rails and similar Web application frameworks were the wave of the future, and PHP frameworks, including those recognized as template Rails, began to emerge rapidly. CakePHP was the first to appear in 2005, and Symfony, CodeIgniter, Zend Framework and Kohana(a branch of CodeIgniter) followed shortly after. Yii came in 2008, Slim came in 2010. FuelPHP and Laravel also appeared in 2011, neither of which was perfect, but could serve as an alternative.
Some of these frameworks are more like Rails, focusing on database object ORM, MVC architecture, and other tools for rapid development. Other frameworks, such as Symfony and Zend, are more about enterprise design solutions and e-commerce.
Advantages and disadvantages of the CodeIgniter framework
CakePHP and CodeIgniter are two of the older PHP frameworks that were more or less inspired by Rails. CodeIgniter’s reputation rose rapidly, and by 2010 it was arguably the most popular PHP framework.
CodeIgniter is easy to use, has amazing documentation and a strong community. But it was slow to adopt modern technology and advanced modes, and as the framework world evolved and PHP tools improved, CodeIgniter began to lag behind in advanced technology and out-of-the-box functionality. Unlike many other frameworks, CodeIgniter was managed by a company that had a hard time keeping up with new PHP5.3 features such as namespaces and the migration to Github and later Composer. In 2010, Laravel founder Taylor Otwell was not satisfied with using CodeIgniter, so he started writing his own framework.
Laravel 1, 2, 3
The first beta version of Laravel 1 was released in June 2011 and was written from the ground up. The Eloquent features include: custom ORM(Eloquent), closure based routing, an extension module system, forms validation, authentication assistant, and more.
Early Laravel grew rapidly, with Laravel2 and 3 released in November 2011 and February 2012, respectively. They include: controllers, unit tests, command-line tools, inversion of Control (IoC) containers, Eloquent relationships, and migrations.
Laravel 4
For Laravel4, Taylor rewrote the entire framework from scratch. At the time Composer, an advanced package management tool, was showing signs of becoming an industry icon, and Taylor saw the value in rewriting the framework as a collection of components, distributed and bundled together by Composer.
Taylor developed a series of components under the code Illuminate, and in May 2013, released Laravel4 with a new structure. Instead of bundling most of the code for download, Laravel now pulls most of the components via Composer from Symfony(another framework for publishing components for use by other components) and Illuminate components.
Laravel4 also introduces queues, mail components, Facades, and database migration. Since Laravel currently relies on Symfony components, it announced that Laravel will reflect Symfony’s plans for the next six months.
Laravel 5
Laravel 4.3 was scheduled for release in November 2014, but as development progressed, it became clear that the changes were significant enough to warrant a major release, so Laravel 5 was released in February 2015. Laravel 5 improved directory structure, removed forms and HTML helpers, introduced Contract interfaces, numerous new attempts, Socialte for social media authentication, Elixir for resource compilation, scheduler for simplified Cron,.env for simplified environment management, There are also form requests and a new REPL(Read-evaluate-print loop).
What makes Laravel special
So what’s different about Laravel? Why is it worth having more than any other framework anyway? Because all of their components come from Symfony, right? Let’s take a look at what makes Laravel special.
The philosophy of the Laravel
You only have to read Laravel’s promotional materials and README to see why it exists. Taylor likes to use light-related terms for his work, like Illuminate and Spark.
The two values that this framework has to spread are speed and happiness. At the heart of Laravel is providing better equipment to support developers. The goal is to provide clear, simple, elegant code and features that help developers quickly learn, start and develop, and write simple, clear and durable code.
The concept for developers is already evident in the official Laravel material. It says: Let developers have fun writing the best code. Developers are happy from download to deployment was the unofficial slogan of the time.
Of course, any tool or framework says it likes to make developers happy. But making developer happiness a primary concern, not a secondary one, has had a huge impact on Laravel’s style and decision-making process. Where other frameworks might have architectural purity as their primary goal, or be compatible with the goals and values of corporate development teams, Laravel’s primary focus is to serve individual developers.
How does Laravel achieve developer happiness
Having said that making developers happy is one thing and doing it is another, ask yourself: what are the things in a framework that are most likely to make us unhappy, and what are the things that are most likely to make us happy? Laravel tries to make life easier for developers.
Laravel is a rapid application development framework. This also means that it focuses on a simple learning curve and minimizes the steps between starting an application and launching it. These are some of the most common tasks in building a Web application, from database interaction to authentication, queues, mail, and caching, all made easier by Laravel’s components. Laravel’s components are not only great, but also provide a consistent API and predictable structure. That means that when you write something new with Laravel, you might end up saying it works.
Without ending with this framework, Laravel also provides a complete ecosystem of tools for building and launching applications. You can use Homestead and Valet for local development, Forge for server management, and Envoyer for advanced deployment. There are a few additional component packages: Cashier for payments and subscriptions, Echo for WebSocket, Souct for search, Passport for API authentication, Socialite for social login, and Spark for bootstrap Sass. Laravel tries to do what developers repeat so that they can do something else.
Second, Laravel focuses on convention over configuration, meaning that if you are willing to use some of Laravel’s default configurations, you can also do a lot less work than if you have to define all the configurations, even if you use the recommended configuration framework. Frameworks built on Laravel take less time than those built on most other PHP frameworks.
Laravel is deeply concerned with simplicity. With Laravel it is possible to use dependency injection, MOKC, data mapping schema, Repository, command line queries, and more complex structural queries if you will. Whereas other frameworks might suggest using these tools and structures for every project, Laravel and its documentation and community tend to start with the simplest implementations, such as global functions, facade, ActiveRecord, etc. This allows developers to create the simplest applications to meet their needs.
One interesting source of Laravel’s differentiation is that its creators and community are more associated with, and inspired by, Java than Ruyb and Rails or functional programming languages. Another powerful trend in modern PHP is the tendency to be cumbersome and responsible, incorporating more Java features. But Laravel leans toward the other side, embracing expressions, dynamics, and simple practice-oriented and linguistic features.
Laravel community
If the series is your first exposure to the Laravel community, then you have something special to look forward to. A prominent feature of Laravel has contributed to its growth and success. From Jeffrey Way’s Laracasts video tutorials to Laravel News to Slack and IRC channels, from Twitter to bloggers, to Laracon conferences, Laravel has a vibrant community.
Taylor understood early on from Laravel that a successful open source project requires two things: good documentation and a welcoming community. Laravel did both of those things.
How does Laravel work
So far, everything that has been said here has been completely abstract. What about the code, you might ask? Let’s take a look at a simple application so you can see how Laravel actually works.
// File: routes/web.php <? php Route::get('/', function(){ return 'Hello, World! '; })? >Copy the code
The simplest action you can do in a Laravel app is to define a route and return a result when someone accesses that route. If you initialize a Laravel application on your own machine and define the route above, you can launch your site in the public directory and access it yourself. The result of that interview is
Hello World!Copy the code
Does it look like a controller? How does the controller work
// routes/web.php <? php Route::get('/','WelcomeController@index'); // app/Http/Controllers/WelcomeController.php <? php namespace app\Http\Controllers; class WelcomeController { public function index() { return 'Hello, World! '; }}Copy the code
Why Laravel?
So, with all that said, you can see why Laravel?
Because Laravel helps you bring your ideas to life without wasting code, uses modern coding standards, is surrounded by a vibrant community, and has a strong tool ecosystem.
So we, as developers, should be happy. Isn’t it? ^_^