自定义头部导航条

从版本1.5.6开始,可以在顶部导航条上添加html元素了, 打开app/Admin/bootstrap.php

  1. use Encore\Admin\Facades\Admin;
  2. Admin::navbar(function (\Encore\Admin\Widgets\Navbar $navbar) {
  3. $navbar->left('html...');
  4. $navbar->right('html...');
  5. });

leftright方法分别用来在头部的左右两边添加内容,方法参数可以是任何可以渲染的对象(实现了HtmlableRenderable接口或者包含__toString()方法的对象)或字符串

左侧添加示例

举个例子,比如在左边添加一个搜索条,先创建一个blade视图resources/views/search-bar.blade.php

  1. <style>
  2. .search-form {
  3. width: 250px;
  4. margin: 10px 0 0 20px;
  5. border-radius: 3px;
  6. float: left;
  7. }
  8. .search-form input[type="text"] {
  9. color: #666;
  10. border: 0;
  11. }
  12. .search-form .btn {
  13. color: #999;
  14. background-color: #fff;
  15. border: 0;
  16. }
  17. </style>
  18. <form action="/admin/posts" method="get" class="search-form" pjax-container>
  19. <div class="input-group input-group-sm ">
  20. <input type="text" name="title" class="form-control" placeholder="Search...">
  21. <span class="input-group-btn">
  22. <button type="submit" name="search" id="search-btn" class="btn btn-flat"><i class="fa fa-search"></i></button>
  23. </span>
  24. </div>
  25. </form>

然后加入头部导航条:

  1. $navbar->left(view('search-bar'));

右侧添加示例

导航右侧只能添加<li>标签, 比如要添加一些提示图标,新建渲染对象app/Admin/Extensions/Nav/Links.php

  1. <?php
  2. namespace App\Admin\Extensions\Nav;
  3. class Links
  4. {
  5. public function __toString()
  6. {
  7. return <<<HTML
  8. <li>
  9. <a href="#">
  10. <i class="fa fa-envelope-o"></i>
  11. <span class="label label-success">4</span>
  12. </a>
  13. </li>
  14. <li>
  15. <a href="#">
  16. <i class="fa fa-bell-o"></i>
  17. <span class="label label-warning">7</span>
  18. </a>
  19. </li>
  20. <li>
  21. <a href="#">
  22. <i class="fa fa-flag-o"></i>
  23. <span class="label label-danger">9</span>
  24. </a>
  25. </li>
  26. HTML;
  27. }
  28. }

然后加入头部导航条:

  1. $navbar->right(new \App\Admin\Extensions\Nav\Links());

或者用下面的html加入下拉菜单:

  1. <li class="dropdown notifications-menu">
  2. <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
  3. <i class="fa fa-bell-o"></i>
  4. <span class="label label-warning">10</span>
  5. </a>
  6. <ul class="dropdown-menu">
  7. <li class="header">You have 10 notifications</li>
  8. <li>
  9. <!-- inner menu: contains the actual data -->
  10. <ul class="menu">
  11. <li>
  12. <a href="#">
  13. <i class="fa fa-users text-aqua"></i> 5 new members joined today
  14. </a>
  15. </li>
  16. <li>
  17. <a href="#">
  18. <i class="fa fa-warning text-yellow"></i> Very long description here that may not fit into the
  19. page and may cause design problems
  20. </a>
  21. </li>
  22. <li>
  23. <a href="#">
  24. <i class="fa fa-users text-red"></i> 5 new members joined
  25. </a>
  26. </li>
  27. <li>
  28. <a href="#">
  29. <i class="fa fa-shopping-cart text-green"></i> 25 sales made
  30. </a>
  31. </li>
  32. <li>
  33. <a href="#">
  34. <i class="fa fa-user text-red"></i> You changed your username
  35. </a>
  36. </li>
  37. </ul>
  38. </li>
  39. <li class="footer"><a href="#">View all</a></li>
  40. </ul>
  41. </li>

更多的组件可以参考Bootstrap