Laravel 4 Unable to Read Package Configuration File

I was trying to add a configuration file to an existing Laravel 4 package (revisionable) to help improve the functionality. But no matter what I tried I could not get the package to read from the src/config/config.php file.

Turns out the issue was caused by the package not having a service provider. I'm not 100% why this made a difference but by adding the service provider file and adding it to the service providers within app/config/app, the config would read.

Here's the service provider that actually made it work - specifically the $this->package('venturecraft/revisionable'); code within the register() function

<?php
namespace VenturecraftRevisionable;

use IlluminateSupportServiceProvider;

class RevisionableServiceProvider extends ServiceProvider {

	/**
	 * Indicates if loading of the provider is deferred.
	 *
	 * @var bool
	 */
	protected $defer = false;

	/**
	 * Register the service provider.
	 *
	 * @return void
	 */
	public function register()
	{
		$this->package('venturecraft/revisionable');
	}

	/**
	 * Get the services provided by the provider.
	 *
	 * @return array
	 */
	public function provides()
	{
		return array();
	}
}

Then to read the config file, you can just use:

Config::get('revisionable::file.key');

// or if you only have one config file named config.php
Config::get('revisionable::key');

I'd love to know exactly why it works like this so please feel free to shed your Laravel knowledge in the comments below.

Thanks to Zennon Gosalvez's article which helped lead me in the right direction.


comments powered by Disqus