visit
It’s been a while (Sept 8th 2020, specifically) since Laravel 8 was finally released, but I believe that its features need to be brought to light again since Laravel has always stood out when it comes to web development. It is the most popular framework of PHP, which itself is one of the pioneer programming languages.
With almost and counting, Laravel is also one of the most trending repositories on GitHub. It gained more popularity after the release of features like Artisan (Command Line Interface), support for the database system, migrations, and bundles.
Some of the popular websites are built with Laravel, including BBC, OnePlus, 9GAG, and so many more. It’s suitable for developing all kinds of web applications ranging from startups to enterprise level.
With a lot of built-in functionalities that allow developers to work with ease, Laravel also comes with official packages that opens up so many possibilities. Before we talk about what was introduced in Laravel 8, let’s look at what it’s already capable of.
Template Engine
Laravel is highly recognized for its built-in lightweight templates that can be used to create amazing layouts using dynamic content seeding. On top of that, it provides multiple widgets using the CSS and Javascript code with robust structures. Laravel templates are especially designed so that you can create simplest to the most complex layouts with distinctive sections.
MVC Architecture Support
With Laravel, you get support for MVC architecture pattern which makes sure that business logic and presentation layers are separate. Being able to split roles in your project, isolate responsibility, MVC pattern of Laravel has a lot of such built-in functions that helps improve application performance and increases security as well as scalability.
Eloquent ORM (Object Relational Mapping)
There are several reasons , one of which is its articulate Object Relational Mapping (ORM) system that consists of a simple PHP Active Record implementation. This allows web app developers to write database queries with PHP syntax rather than writing SQL code. An ORM is significantly faster than other PHP frameworks.
Security
Laravel offers strong web application security. It uses hashed and salted password mechanisms because of which the password would never be saved as a plain text in the database. It also uses the “Bcrypt Hashing Function” to generate an encrypted password. Additionally, it uses prepared SQL statements that prevent SQL injection attacks.
Artisan
Laravel provides a built-in command-line tool called Artisan that helps you automate the majority of monotonous programming tasks. These Artisans can be used to create the database structure, a skeleton code, and manage migration so it is a pretty easy-to-manage database system. In addition, Artisan even helps Laravel developers to create their own commands and use them as required.
Libraries & Modular
Laravel arrives with pre-installed Object-Oriented and Modular libraries that are not available in many other PHP frameworks. For instance, the Authentication library with features such as checking active users, password reset, Bcrypt hashing, CSRF (Cross-site Request Forgery) protection, and encryption.
Laravel 8 was the latest version of the Laravel framework, that was released on September 8th. It comes with some amazing new features and even has a guide . Taylor Otwell, the creator of Laravel, announced some of those new features in his LARACON presentation.
Here’s a summary of some of the new capabilities announced of the app. Let’s take a look at some of those great new features:-
app/Models Directory
Laravel 8 will now arrive with an
app/models
directory, instead of leaving model class in the root app
directory as in previous versions of Laravel. According to a poll run by Taylor, over 80% of developers were creating an app/models
directory themselves anyway.If you use any of the artisan generator commands, maybe like a
php artisan make:model
that can create a model class for you, it will create a new model for you inside the new app/models
directory. However, if you wish to keep your models in your
app
directory and delete the new models directory, the generator commands will comply with that and create the model classes in your app directory.New landing page
The page you see when you visit the homepage on a fresh install has had a renovation. It is now built with and also comes in light/dark versions. It has links to several community sites and various SaaS products from Laravel as well. If you’d like to get your hands on some new merch, there is a link to the new Laravel shop there as well.
Controllers namespace prefix removed
In the earlier versions of Laravel, there was a property in the RouteServiceProvider.php called
$namespace
which was used to prefix the namespace of your controllers automatically (applying App\Http\Controllers
). If you were using the callable syntax in your
web.php
routes file, Laravel would've double prefixed your namespaces. Fortunately, this property has been removed from Laravel 8, so you can now import your controller classes in your routes file without issue.Route caching improvements
Hopefully, you were using the route caching in your application already (running
php artisan route:cache
generates a PHP file with an array that contains all your routes, which then Laravel uses for routing because it's faster than having to parse your routes file(s) on every request).Up until now, however, if you had any closures in your routes, or even if a package registered a route with a closure, it would have caused the route caching to fail. With Laravel 8, you get support for route caching for closure based routes!
Blade component attributes
If you were to extend a Blade component (e.g. having a component called DangerButton, that extended another component called Button) in Laravel 7, the child button wouldn't have had the
$attributes
passed down to it. In Laravel 8, all child components will have the $attributes
available, which makes it easier to build extended components.Cleaner syntax for closure based event listeners
In previous Laravel versions, while registering a closure based event listener, you would’ve had to first define the event class, then register the closure, and probably type hint the event class for the closure e.g.:
In Laravel 8, you can skip the first definition of the event class since the framework is able to infer it from the type hinted argument - e.g.:
Queueable anonymous event listeners
In Laravel 8, you will be able to send a closure based job to the queue from your model event callbacks e.g.:
In previous Laravel versions, it wasn’t possible to make this happen until you created an event class and event listener, using the ShouldQueue trait. This new feature makes the process quicker and actually introduces the first namespaced function into the Laravel framework,
Illuminate\Events\queueable
.Maintenance mode: secret access
If you use the
artisan down
/ artisan up
commands to put your site into maintenance mode but still want to give access to some people (maybe yourself, other developers, etc), the only way this is possible is via IP whitelisting. It wouldn’t work well if you were to grant access to lots of people, or if you have a dynamic IP address that regularly changes. That changes with Laravel 8! You will now able to use a "secret" flag when you put your site into maintenance mode - e.g:
The value of the secret flag becomes a route while your site is in maintenance mode. If you were to then navigate to that, the framework will set a cookie that instructs your app to ignore the maintenance mode when you access it. It lasts for several hours and redirects you to the homepage of your app, which you can then browse as a normal website.
Exponential backoff for job failures
You can now add a new backoff() method to your job classes which returns an array of integers to decide the acceptable wait time between job attempts if it fails - e.g:
In the above example, if the job failed on its first attempt, it would wait 1 second before trying again. If the job fails again, it would wait 5 seconds before attempting again. Similarly, it’ll wait for 10 seconds before attempting again. This could come in handy when you're working with a rate limited API to increase the wait each time the job fails.
There are several more features that Taylor and the team have certainly been busy with. Even though it’s been a while since the version launched, it’s important to shed some light on the core features of Laravel 8.
You can watch Taylor's talk or something similar in the Web Development Industry to keep yourself updated with what’s going on. If any of this is too technical for you to understand, you can always hire a Laravel Developer to help you build a web app.