Laravel 11 Streamlined Configuration Files
One of the standout features of Laravel 11 is its streamlined configuration files. Initially, all configuration files were removed from the default Laravel installation. However, just weeks before the release, Taylor Otwell (Laravel's creator) decided to re-include a simplified set of configuration files. The best part? You now have the flexibility to remove any files or settings you don’t need.
This change is beneficial in several ways. It reduces unnecessary bloat in your application, and you can ensure that you only have the settings that are crucial for your project. But, you need to be mindful about keeping your configuration files up-to-date, as Laravel’s internal defaults change over time.
Let's take a closer look at how this works and how you can take advantage of it to create a leaner application.
Merging Configuration Files
Internally, Laravel merges your custom configuration files with the framework's default ones. So, for example, if your app has a config/database.php
file, Laravel will merge it with the internal config/database.php
file, which contains the default configuration settings.
The key thing here is the merge. On the surface, this is a shallow merge, which means it combines top-level settings. This allows you to further slim down your configuration by removing any top-level options that you don’t use. Any options in your configuration file will still be automatically merged with Laravel's internal defaults.
Example: Customizing config/app.php
Let’s take a look at a quick example. Consider the following config/app.php
file within a Laravel 11 application:
The resulting configuration would include all of the core app configuration options (e.g., app.name
, app.env
, app.debug
, etc.) with:
-
app.timezone
overwritten withAsia/Phnom Penh
-
app.custom_option
added asfoo
This merge is simple and works great for files with top-level options. However, some configuration files have nested options, such as the "driver" options.
Merging Nested Options
Laravel takes the merging process a step further for certain nested options, such as database.connections
, filesystem.disks
, and others. While Laravel doesn't perform a deep, recursive merge, it merges common nested options to help reduce redundancy.
For instance, if you're only using certain database drivers (e.g., the default mysql
and testing
drivers, along with a custom mysql_replica
driver), you can slim down your config/database.php
file as shown below:
In this case, only the mysql_replica
driver configuration is included, which means your configuration is much leaner than including all default drivers.
Keeping or Removing Default Configurations
While you’re free to keep the full set of default configuration files with all their options, Laravel’s new structure provides a great opportunity for developers who prefer a more minimal setup. If you want to reduce noise in your configuration files and only include true customizations, this streamlined approach will help you achieve that.
Laravel 11's streamlined configuration files allow you to customize only what you need, reducing unnecessary bloat in your application. Whether you prefer keeping the full set of configuration files or slimmed-down versions, this feature gives you more control over your Laravel setup.