What is the Laravel framework and why should I use it?
Laravel is a framework for PHP. A framework creates a standard for other programmers to follow. There are a million and one ways to build things with a programming language, especially PHP, and one way is not necessarily better than another way.
There are also many design patterns. Frameworks force you to follow a specific design pattern. Laravel does a fantastic job at separating concerns. You may have heard of models, views, and controllers, but how exactly do you create one, and where do you put it? What about error handling and logging? Where is this config file supposed to go? Should view templates go in this folder or that one? All of these questions are answered by Laravel. When you create a new Laravel project, you get a thousand different decisions made for you. Laravel does its best to force you to follow good coding practices. When I say a thousand, I do mean a thousand. Laravel is a little bit heavy. It has to make a small compromise in order to be the most enjoyable and easy framework for PHP developers to use.
It installs about a thousand differing composer packages. However, don’t let this dissuade you from using Laravel for one moment. Unless you are building the next Facebook or Bank of America web application, Laravel will work just fine. Laravel has a great caching system for when you need to optimize your web application.
What can Laravel do?
We can learn a lot about Laravel just by looking at the folders it creates by default.
In your app folder, you have all of the server-side logic for your application. The Http folder has a folder called controllers. This, of course, is where you create any controllers for your application. Controller classes receive data from the client in the form of a request, like data from a form submission or a GET request for a new page (a view).
You no longer have to wonder where to put your controllers or even what a controller is. When the client makes a request to the server, Laravel figures out which controller to send the request using routes.
Speaking of routes, creating routes for your controllers is extremely straightforward since Laravel takes care of the heavy lifting. Just specify a route and point it to a controller. Even if you have hundreds of routes, it will be easy to organize them. Each route is only one line of code, and that’s exactly how it should be.
In the app folder, you also have a very useful folder called Mail. You would be surprised how many notifications you need to create for a decent web app. Laravel also has a Notifications folder which makes sending other notifications like SMS super simple.
There’s no folder for models, but the idea of models is there. I would recommend you create a folder for your models. In Caravel, Models are classes that model data from a database. Each class represents a table in the database. The specific functions to create relationships between tables and to get data from those tables.
These are just a couple of the useful features of Laravel.
Learning Laravel, a PHP framework, is a great goal that will make you a lot more valuable as a web developer.