AppServiceProvider.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Providers;
  3. use Carbon\Carbon;
  4. use Illuminate\Support\Facades\Config;
  5. use Illuminate\Support\Facades\Validator;
  6. use Illuminate\Support\ServiceProvider;
  7. class AppServiceProvider extends ServiceProvider
  8. {
  9. /**
  10. * Bootstrap any application services.
  11. *
  12. * @return void
  13. */
  14. public function boot()
  15. {
  16. //设置时间
  17. Carbon::setLocale(Config::get('app.locale'));
  18. Validator::extend('greater_than_field', function($attribute, $value, $parameters, $validator) {
  19. $min_field = $parameters[0];
  20. $data = $validator->getData();
  21. $min_value = $data[$min_field];
  22. return $value > $min_value;
  23. });
  24. Validator::replacer('greater_than_field', function($message, $attribute, $rule, $parameters) {
  25. return str_replace('_', ' ' , 'The '. $attribute .' must be greater than the ' .$parameters[0]);
  26. });
  27. }
  28. /**
  29. * Register any application services.
  30. *
  31. * @return void
  32. */
  33. public function register()
  34. {
  35. //
  36. }
  37. }