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

coxw's avatar
Level 1

How to use a package config

I'll start by saying I have read all of the docs on the Laravel site, but I am still confused.

http://laravel.com/docs/4.2/packages#package-configuration

Simply put Config::get('package::file.option'); should work.

I have a custom package, at truckr/sdk. First, the docs never mention the vendor name so I have assumed this means my package would follow the name 'sdk'. I have a vendor/truckr/sdk/src/config/config.php file that this should be able to read my 'endpoint' variable from within the config.php array. That being said, it looks like this should work: Config::get('sdk::config.endpoint');

I get an empty array. The goal of this is to alter my endpoint for the SDK url within the package that is configurable at the deploy. My deploys are generating these config files in app/config/truckr/sdk . Now, I have also tried every variation I can imagine.

Config::get('truckr/sdk::config.endpoint'); Config::get('truckr.sdk::config.endpoint'); Config::get('truckr/sdk::endpoint'); Config::get('sdk::endpoint');

You get my drift. Am I not namespacing this? It seems like I am not registering the config file, or its not autoloading, or I'm just being dumb. I'm open to ideas.

0 likes
4 replies
MThomas's avatar

I do believe that this is not the right location to publish your package vendor files in L4.2: 'app/config/truckr/sdk'

I do believe it must be something like 'app/config/vendor/truckr/sdk'

coxw's avatar
Level 1

@RayRutjes I tried adding it to the ServiceProvider of the package as well. My package works great in all other aspects - it's only when I try to introduce configs to it.

<?php

namespace Truckr\Integration\Laravel;

use Truckr\SDK;
use GuzzleHttp\Client;
use Illuminate\Support\ServiceProvider;

class SDKServiceProvider extends ServiceProvider{

    public function register(){
        $this->app->bindShared('truckr-sdk', function(){
            return new SDK(
                new Client(['base_url' => SDK::BASEURL])
            );
        });
    }

    public function boot(){
       /* got desparate, added this to try your suggestion */
        $this->package('truckr/sdk');
        include __DIR__.'/../../config/config.php';
    }
}

Here is what the structure looks like. Again - I'm sure it's something small I'm not doing. I've followed the same structure as other packages and here is what it looks like:

Directory Structure

@MThomas Thanks for the suggestion. I'm not sure where you set. I use artisan to publish it locally and it puts it there, along with all of the other published package configs in the same structure (that work fine)

powerupneo's avatar

This in the register() method worked for me

Config::package('vendor/package', 'package');

Please or to participate in this conversation.