Exemplo n.º 1
0
 /**
  * @param UserModel $user
  * @param array     $blueprint
  * @return static
  */
 public static function make(UserModel $user, array $blueprint = null)
 {
     if (is_null($blueprint)) {
         $blueprint = \Config::get('admin.menu', array());
     }
     $menu = new static();
     $child = null;
     foreach ($blueprint as $key => $value) {
         if (is_array($value)) {
             //有子目录
             /**
              * $key = '用户'
              * $value = array(
              * '查看' => 'admin::dashboard' ,
              * '新建' => 'admin::dashboard' ,
              * '删除' => 'admin::dashboard' ,
              * )
              *
              * $menu->submenu = new Menu( $user , $value )
              */
             $child = static::make($user, $value);
         } else {
             //无子目录 生成叶子节点
             // $key = '查看'
             // $value = 'admin::dashboard'
             $child = new static();
             $child->setAction($value);
             if (AdminAuthMiddleware::canAccess($value, $user)) {
                 $child->setValid(true);
             } else {
                 $child->setValid(false);
             }
         }
         if ($child) {
             $menu[$key] = $child;
             if ($child->isActive()) {
                 $menu->setActive();
             }
         }
     }
     return $menu;
 }
Exemplo n.º 2
0
    /**
     * 移出回收站按钮 POST方式跳转新页面
     * @param CrudController $controller
     * @param Model $item
     * @return string
     */
    public static function block_btn_restore(CrudController $controller, Model $item)
    {
        if (!method_exists($item, 'trashed')) {
            return '';
        }
        if (false == $item->trashed()) {
            return '';
        }
        $url = $controller->redirectToMethodUrl('postRestore', $controller);
        $action = 'admin::' . $controller::getActionPrefix() . '.remove.restore';
        if (AdminAuthMiddleware::canAccess($action, \Auth::user())) {
            $disabled = '';
        } else {
            $disabled = 'disabled';
        }
        $id = $item->getKey();
        $token = csrf_token();
        $form = <<<FORM
<a class='btn btn-sm btn-danger'
  data-attr-confirm='确定要恢复吗'
  data-attr-submit-url='{$url}'
  data-attr-item-id='{$id}'
  data-attr-csrf-token='{$token}'
href='javascript:;' onclick='javascript:ktable.submit_form(this);' {$disabled}>
<span class='glyphicon glyphicon-repeat'></span>
</a>
FORM;
        return $form;
    }