Skip to content

Instantly share code, notes, and snippets.

@atorscho
Last active August 29, 2015 14:27
Show Gist options
  • Save atorscho/6e04ae2248dbf04631cc to your computer and use it in GitHub Desktop.
Save atorscho/6e04ae2248dbf04631cc to your computer and use it in GitHub Desktop.
Service Provider for a Laravel 5 package.
<?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