AppServiceProvider.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Providers;
  3. use App\Models\Chat;
  4. use App\Models\Message;
  5. use Carbon\CarbonImmutable;
  6. use Illuminate\Support\Facades\Date;
  7. use Illuminate\Database\Eloquent\Model;
  8. use Illuminate\Database\Eloquent\Relations\Relation;
  9. use Illuminate\Http\Resources\Json\JsonResource;
  10. use Illuminate\Support\Facades\Http;
  11. use Illuminate\Support\ServiceProvider;
  12. class AppServiceProvider extends ServiceProvider
  13. {
  14. /**
  15. * Register any application services.
  16. */
  17. public function register(): void
  18. {
  19. if ($this->app->environment('local') && class_exists(\Laravel\Telescope\TelescopeServiceProvider::class)) {
  20. $this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
  21. $this->app->register(TelescopeServiceProvider::class);
  22. }
  23. }
  24. /**
  25. * Bootstrap any application services.
  26. */
  27. public function boot(): void
  28. {
  29. Date::use(CarbonImmutable::class);
  30. // As there are concerned with application correctness
  31. // leave them enable all the time.
  32. Model::preventAccessingMissingAttributes();
  33. Model::preventSilentlyDiscardingAttributes();
  34. // Since this is a performance concern only, don't halt
  35. // production for violations.
  36. Model::preventLazyLoading(!$this->app->isProduction());
  37. Relation::enforceMorphMap([
  38. 'chat' => Chat::class,
  39. 'message' => Message::class
  40. ]);
  41. JsonResource::withoutWrapping();
  42. Http::macro('inference', fn() => Http::baseUrl(config('services.inference.host'))->timeout(120));
  43. }
  44. }