AppServiceProvider.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Providers;
  11. use Carbon\Carbon;
  12. use Illuminate\Support\Facades\App;
  13. use Illuminate\Support\Facades\Validator;
  14. use Illuminate\Support\ServiceProvider;
  15. class AppServiceProvider extends ServiceProvider
  16. {
  17. /**
  18. * Register any application services.
  19. */
  20. public function register()
  21. {
  22. }
  23. /**
  24. * Bootstrap any application services.
  25. *
  26. * @return void
  27. */
  28. public function boot()
  29. {
  30. if (App::getLocale() == 'zh_CN') {
  31. Carbon::setLocale('zh');
  32. }
  33. $this->registerObservers(); // 注册观察者
  34. Validator::extend('mobile', function ($attribute, $value, $parameters) {
  35. return preg_match('/^1[3456789][0-9]{9}$/', $value);
  36. }, T('mobile'));
  37. }
  38. protected function registerObservers(): void
  39. {
  40. }
  41. }