Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gitwithravish's avatar

Best way to read config file within a service provider

I have a custom package like this in my project

App
    Services
      MyPackage
        Exceptions
        config
            config_to_be_published.php
            config_for_internal_use.php
        Facades
        ServiceProvider.php
        Service.php

Here, what is the best way to access config_for_internal_use.php within Service.php ?

Usually in laravel we would use config() to read the configs.

How should I go about this?

0 likes
1 reply
GeordieJackson's avatar

In the service provider, just use:

$this->mergeConfigFrom('path_to_your_config', 'your_key_name');

and it will add your config settings to config();

Please or to participate in this conversation.