PaginationServiceProvider.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Illuminate\Pagination;
  3. use Illuminate\Support\ServiceProvider;
  4. class PaginationServiceProvider extends ServiceProvider
  5. {
  6. /**
  7. * Bootstrap any application services.
  8. *
  9. * @return void
  10. */
  11. public function boot()
  12. {
  13. $this->loadViewsFrom(__DIR__.'/resources/views', 'pagination');
  14. if ($this->app->runningInConsole()) {
  15. $this->publishes([
  16. __DIR__.'/resources/views' => $this->app->resourcePath('views/vendor/pagination'),
  17. ], 'laravel-pagination');
  18. }
  19. }
  20. /**
  21. * Register the service provider.
  22. *
  23. * @return void
  24. */
  25. public function register()
  26. {
  27. Paginator::viewFactoryResolver(function () {
  28. return $this->app['view'];
  29. });
  30. Paginator::currentPathResolver(function () {
  31. return $this->app['request']->url();
  32. });
  33. Paginator::currentPageResolver(function ($pageName = 'page') {
  34. $page = $this->app['request']->input($pageName);
  35. if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) {
  36. return (int) $page;
  37. }
  38. return 1;
  39. });
  40. }
  41. }