Bootstrap.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Encore\Admin\Middleware;
  3. use Encore\Admin\Admin;
  4. use Encore\Admin\Form;
  5. use Encore\Admin\Grid;
  6. use Illuminate\Http\Request;
  7. class Bootstrap
  8. {
  9. public function handle(Request $request, \Closure $next)
  10. {
  11. Form::registerBuiltinFields();
  12. Grid::registerColumnDisplayer();
  13. if (file_exists($bootstrap = admin_path('bootstrap.php'))) {
  14. require $bootstrap;
  15. }
  16. if (!empty(Admin::$booting)) {
  17. foreach (Admin::$booting as $callable) {
  18. call_user_func($callable);
  19. }
  20. }
  21. $this->injectFormAssets();
  22. if (!empty(Admin::$booted)) {
  23. foreach (Admin::$booted as $callable) {
  24. call_user_func($callable);
  25. }
  26. }
  27. return $next($request);
  28. }
  29. /**
  30. * Inject assets of all form fields.
  31. */
  32. protected function injectFormAssets()
  33. {
  34. $assets = Form::collectFieldAssets();
  35. Admin::css($assets['css']);
  36. Admin::js($assets['js']);
  37. }
  38. }