brazorf
brazorf

Reputation: 1951

Laravel4 unable to read a package published config file, default is used instead

I've developed a package that ive imported in a new project using composer. Its directory structure is like the following

vendor
    package-name
        src
            config
                config.php
... more elements

I have then published the configuration file using

php artisan config:publish vendor/package-name

The file has been copied to

app
    config
        packages
            vendor
                package-name
                    config.php

Configuration in the vendor directory is like

array(
    'user' => array( 'table' => 'users' ),
);

Configuration in the published directory is like

array(
    'user' => array( 'table' => 'anotherName' ),
);

Now, when i access the configuration like

Config::get('package-name::user.table');

The value 'users' is returned. It seems like the published file is being ignored. Why?

Upvotes: 2

Views: 488

Answers (1)

Kryten
Kryten

Reputation: 15760

We're going to need more information to definitively answer this question, but here's an explanation of some of the things that might be going wrong.

When you register your package in the service provider, you call the following method:

$this->package("vendor/package");

This is the default way of doing it, and if you've done it this way, you can access the config via $value = Config::get("package::config.key");. In this case, the package name (as spelled out in the call to the package() method) is the namespace for the config. However, you must take care that there are no namespace collisions - I'm not sure what would happen if you have two different packages with the same name.

If you want to define a custom namespace for your package config, you can do so like this:

$this->package("vendor/package", "mycustomnamespace");

Then you can refer to config items with

$value = Config::get("mycustomnamespace::config.key");

To further diagnose this problem, I'd start with a custom namespace - can you get it to work by specifying a custom namespace? If so, I'd start looking for conflicts.

Otherwise, perhaps you can post your service provider and your composer.json file.

Upvotes: 1

Related Questions