Last active
August 29, 2015 14:27
-
-
Save atorscho/6e04ae2248dbf04631cc to your computer and use it in GitHub Desktop.
Service Provider for a Laravel 5 package.
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\Package; | |
use Blade; | |
use Illuminate\Foundation\AliasLoader; | |
use Illuminate\Foundation\Application; | |
use Illuminate\Support\ServiceProvider; | |
class PackageServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap the application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
// Publish View | |
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'package'); | |
$this->publishes([ | |
__DIR__ . '/../resources/views' => base_path('resources/views/vendor/app/package') | |
], 'views'); | |
// Publish Config | |
$this->publishes([ | |
__DIR__ . '/../config/package.php' => config_path('package.php') | |
], 'config'); | |
$this->mergeConfigFrom(__DIR__ . '/../config/package.php', 'package'); | |
} | |
/** | |
* Register the application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// Facade | |
$this->app->bind('package', function (Application $app) { | |
return $app->make(\App\Package::class); | |
}); | |
// Alias | |
$this->app->booting(function () { | |
$loader = AliasLoader::getInstance(); | |
$loader->alias('Package', \Atorscho\Package\PackageFacade::class); | |
}); | |
// Custom Blade Directive | |
Blade::directive('package', function () { | |
return '<?php echo 'package'; ?>'; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment