Issue
I'm deploying my Laravel's projects with git clone
and updating with git pull
It works fine, but each time I deploy, I had to remove the development dependancies from config/app.php
providers
array and aliases
array which is annoying and each time I do composer install --no-dev
, it shows me errors because he didn't found the dev packages.
Solution
You can conditionally load service providers and facades based on the environment in laravel 5.
Service Providers
Service Providers need to be registered in /app/Providers/AppServiceProvider.php
rather than config/app.php
.
// AppServiceProvider.php
public function register()
{
$this->app->bind(
'Illuminate\Contracts\Auth\Registrar',
'App\Services\Registrar'
);
if ($this->app->environment('production')) {
$this->app->register('App\Providers\ProductionProvidersGoHere');
} else {
$this->app->register('App\Providers\DevelopmentProvidersGoHere');
}
}
For a tutorial have a look here: https://mattstauffer.co/blog/conditionally-loading-service-providers-in-laravel-5
Facades
Facades can be conditionally loaded with the AliasLoader
.
/**
* List of only Local Enviroment Facade Aliases
* @var array
*/
protected $facadeAliases = [
'Debugbar' => 'Barryvdh\Debugbar\Facade',
];
/**
* Load additional Aliases
* Base file Alias load is /config/app.php => aliases
*/
public function registerFacadeAliases()
{
$loader = AliasLoader::getInstance();
foreach ($this->facadeAliases as $alias => $facade)
{
$loader->alias($alias, $facade);
}
}
Here is a nice tutorial for this too: http://blog.piotrows.pl/en/laravel-5-load-serviceprovider-depend-on-env-file/
// Edit
added facades:
Thanks to @Sn0opr for pointing me into this.
Answered By - Pᴇʜ
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.