Skip to content

Instantly share code, notes, and snippets.

@huiralb
Created September 22, 2017 02:37
Show Gist options
  • Save huiralb/051d06e58f25719ef3dd2765524dc23b to your computer and use it in GitHub Desktop.
Save huiralb/051d06e58f25719ef3dd2765524dc23b to your computer and use it in GitHub Desktop.
Laravel 5.x : register services via service provider
<?php
namespace App\Providers;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
if( count($this->services()) )
{
foreach($this->services() as $class)
{
$this->app->register($class);
}
}
foreach($this->aliases() as $alias => $facade)
{
AliasLoader::getInstance()->alias($alias, $facade);
}
if( env('APP_DEBUG') == true )
{
$this->app->register(\Barryvdh\Debugbar\ServiceProvider::class);
}
}
protected function services()
{
return [
\Intervention\Image\ImageServiceProvider::class,
\Barryvdh\DomPDF\ServiceProvider::class,
];
}
protected function aliases()
{
return [
'Debugbar' => \Barryvdh\Debugbar\Facade::class,
'Image' => \Intervention\Image\Facades\Image::class,
'PDF' => Barryvdh\DomPDF\Facade::class,
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment