What Is Laravel?
Laravel is an open-source PHP framework for building web applications that ships with many of the advanced features and structures you need and takes full advantage of PHP and OOP.
It sums itself up with the slogan “THE PHP FRAMEWORK FOR WEB ARTISANS”, and it lives up to it.
Laravel Features
By design, it lets you build the applications you want while writing genuinely simple, clean code.
Its syntax is very simple and expressive. You won't struggle to get used to it; it is quick to learn.
It is flexible enough to build any kind of web application, from small apps with a handful of operations to large enterprise projects.
It takes full advantage of OOP and PHP, so we work with modern PHP features in a proper OOP way.
Other features that make Laravel what it is:
ORM
Let's first explain what an ORM is: ORM (Object Relational Mapping) is a structure that lets us connect to and manage the database through the (object-oriented) objects in our application. Without writing classic SQL statements, we can access and control the database and run queries through our objects. An ORM is database-agnostic, meaning you use the same code for many databases such as MySQL, SQLite, PostgreSQL, MSSQL and Oracle. It has many advantages, but we won't go into them here.
Laravel uses the Eloquent ORM, the most advanced Active Record implementation.
class Message extends Eloquent {}
$message = Message::find(1);
As you can see, it has a very simple, usable structure. It saves you from writing lots of definitions and long statements.
It fetches the message with id = 1 from the messages table (if you don't specify a table, it picks the table in the database using the plural form, adding an “s”).
Blade Template
It has a template engine called Blade. Again, we can integrate our application with the interface in a very easy and clean way. It is easy to learn, you can build clean, dynamic interfaces, and you don't have to fight your way through tangled HTML and PHP code.
Route
It has a fantastic routing mechanism. You get clean URLs effortlessly and can set up proper access routes for APIs, in a way that won't feel foreign if you know PHP.
Route::get('users', function()
{
return 'Users!';
});
Here you can define your routes, pass them through filters and checks, or point them to your Controller classes. You can even perform your application's work right inside this function without any controller classes at all. (Not recommended)
Migrations (Version Control for the Database)
This is a version control system for the database. Using the Artisan command line, you can add and modify schemas in your application's database. It is a structure that creates or updates your database without going to a database management tool. For example, when you move your application to another environment, instead of trying to build the database by hand, you simply run the structure already in your application and the system is ready.
Unit Test
It lets us create and run unit tests to test our application. We can run the tests we write from the Artisan command line.
Automatic Pagination
Laravel has thought about pagination for us and handled it without putting us to any trouble. We can use it easily and customize it if we want.
Modular package management and Composer
Composer lets you manage your application's third-party packages and add them quickly. With Composer you don't have to worry about your dependencies and packages; instead of dealing with them one by one, you can pull them in very easily.
Performance
It offers caching mechanisms. It is tightly integrated with Redis, practically adopting it as its own. You don't need any extra effort to add Redis to your project; you can configure it quickly and simply.
It comes with many built-in structures such as auth and filters, again offered in a simple way that fits its own architecture. Almost every application needs an auth mechanism, and building one takes extra effort. Laravel didn't skip this either and provides it beautifully, along with similar structures.
It is built on top of many Symfony components.
It is secure and fast, and getting your site up and running is very easy.
It has many more features you'll love, such as taking your site live or putting it into maintenance mode with a single command.
Community
In my opinion, one of the biggest strengths of any framework is its community. It helps in many ways: you can get help and advice when you're stuck, and find great examples and solutions.
It has a very fast-growing community. It is still considered a young framework, so it doesn't yet have as large a community or as much familiarity as, say, CodeIgniter. But it is growing very fast and its popularity increases every day. It has also been well received in Turkey, with a rapidly growing following, and you can even see Laravel in job postings. A very good Turkish documentation has been prepared. You can also reach the local and international forums through its official site. And it would be even better if, rather than just visiting them, you contributed too :)
There is no shortage of documentation; you can learn it in a very short time and get help.
Sites Built with Laravel
You can browse real-world work at http://builtwithlaravel.com/, a site featuring applications built with Laravel.
Server Requirements PHP >= 5.5.9 OpenSSL PHP Extension PDO PHP Extension Mbstring PHP Extension Tokenizer PHP Extension MCrypt PHP Extension
are required.
Installing Laravel
Installing with Composer
composer create-project laravel/laravel laravel-test-proje1 --prefer-dist
This will download and install Laravel into the “laravel-test-proje1″ folder in your current directory.
Installing from GitHub with Git
GitHub address: https://github.com/laravel/laravel
Git clone: https://github.com/laravel/laravel.git
Go to the directory where you want to install it and run
$ git clone https://github.com/laravel/laravel.git
to pull it from the Git repository to our local machine. Then Composer installs Laravel's dependencies. (As we know, we now use Composer for Laravel's dependencies and packages.)
composer install
And that's it, we now have the Laravel framework. If you go to the directory where you downloaded Laravel on your server, you'll see Laravel running from the public folder. If we see a page greeting us with the Laravel logo, everything is fine.
In my example, when I go to “http://localhost/testLaravel/” the Laravel directories are shown.
Note: you may need to give write permission to your server's “app/storage” directory.
We've covered the basics: what Laravel is, its features, why Laravel and how to install it. In upcoming posts we'll cover Laravel in detail and build applications. Personally, I'll be using it heavily both in my own projects and in my professional work.
My Recommendation
Without getting into which framework is better or which one beats which, let me just share my own observations and recommendations about Laravel. We can cover framework comparisons, with their advantages, disadvantages, alternatives and use cases, in a separate post.
It is genuinely easy to learn, and its syntax, structure and simplicity, letting you work as if you were making art with code, win you over completely. You enjoy working with it. Everything in your project is organized and in its place. You don't drown in the structure; you find what you're looking for. Because the code almost talks to you, you understand its language :) When you come back to it, you don't find yourself asking “what on earth did I do here?” (though of course that still depends on how you develop) :) It doesn't just include many built-in structures; it offers them without clutter or bloat. Auth and Redis are just a few of them. It gets your project up and running in no time, so you don't waste time. You forget the old-school way of writing code and step into modern, widely accepted programming. You become familiar with ORM, OOP, template engines, Redis, Composer, unit tests and more, and you feel their benefits first-hand. You get your application up quickly and don't have to build the infrastructure from scratch for every project. Everything is very simple and clean. Much of what you need is gathered in one place.
I think it's at least worth trying and taking a look. Once you start, you'll realize how enjoyable it is and agree with my recommendations.