AppServiceProvider.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Providers;
  3. use App\Billing\Stripe;
  4. use App\Post;
  5. use Illuminate\Foundation\Application;
  6. use Illuminate\Support\ServiceProvider;
  7. class AppServiceProvider extends ServiceProvider
  8. {
  9. const STRIPE = 'billing.stripe';
  10. const STRIPE_KEY = 'services.stripe.key';
  11. protected $defer = true;
  12. /**
  13. * Bootstrap any application services.
  14. *
  15. * @return void
  16. */
  17. public function boot()
  18. {
  19. view()->composer('layouts.sidebar', function ($view) {
  20. $view->with('archives', Post::archives());
  21. });
  22. }
  23. /**
  24. * Register any application services.
  25. *
  26. * @return void
  27. */
  28. public function register()
  29. {
  30. // Use app->singleton(Stripe::class) instead to obtain a reused instance.
  31. // Use app->instance(Stripe::class, $stripe) to replace the instance with another object.
  32. $app2 = $this->app;
  33. $this->app->bind(Stripe::class, function (Application $app) use($app2) {
  34. // Yes, there are 3 ways to get to the app in a service closure.
  35. return new Stripe($this->app['config'][static::STRIPE_KEY]);
  36. });
  37. $this->app->alias(Stripe::class, static::STRIPE);
  38. }
  39. }