Created
September 22, 2017 02:37
-
-
Save huiralb/051d06e58f25719ef3dd2765524dc23b to your computer and use it in GitHub Desktop.
Laravel 5.x : register services via service provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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