AppServiceProvider.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Providers;
  3. use Illuminate\Pagination\Paginator;
  4. use Illuminate\Support\Facades\Schema;
  5. use Illuminate\Support\Facades\Validator;
  6. use Illuminate\Support\ServiceProvider;
  7. use Spatie\QueryBuilder\QueryBuilderRequest;
  8. class AppServiceProvider extends ServiceProvider
  9. {
  10. /**
  11. * Register any application services.
  12. *
  13. * @return void
  14. */
  15. public function register()
  16. {
  17. //
  18. }
  19. /**
  20. * Bootstrap any application services.
  21. *
  22. * @return void
  23. */
  24. public function boot()
  25. {
  26. Paginator::useBootstrap();
  27. Schema::defaultStringLength(191);
  28. Validator::extend('multiple_date_format', function ($attribute, $value, $parameters, $validator) {
  29. $ok = true;
  30. $result = [];
  31. // iterate through all formats
  32. foreach ($parameters as $parameter) {
  33. //validate with laravels standard date format validation
  34. $result[] = $validator->validateDateFormat($attribute, $value, [$parameter]);
  35. }
  36. //if none of result array is true. it sets ok to false
  37. if (!in_array(true, $result)) {
  38. $ok = false;
  39. $validator->setCustomMessages(['multiple_date_format' => 'The format must be one of ' . join(",", $parameters)]);
  40. }
  41. return $ok;
  42. });
  43. }
  44. }