xshaitt

9058 经验值

我想问下如何保证一个账号,只能在一处登录,在第二台设备登录的时候,自动把前面的登录注销掉?没想到什么特别好的方法,请教大家。

node_modules/.bin/webpack-dev-server --inline --hot

2.0写法已经改变了,这是最新的写法

module: {
       rules: [
            {
                test: /\.css$/,
                use: [
                    {
                        loader: "style-loader"
                    },
                    {
                        loader: "css-loader",
                        options: {
                            modules: true
                        }
                    }
                ]
            },
            {
                test: /\.jsx$/,
                loader: "babel-loader", // Do not use "use" here
                exclude: /node_modules/,
                options: {
                    presets: ['es2015','stage-0'],
                    plugins: ['transform-runtime']
                }
            }
        ]
    },

老师,ok了.根据这个 上面的来一遍, 搞定了. 是因为我数据库问题. 但是我还是想知道 在User中的hasRole(); 如何打印数据
http://9iphp.com/web/laravel/laravel-5-acl-define.html

可以请您看下我的代码吗,是真的 跟您视频一起走的.
链接:http://pan.baidu.com/s/1i5Ji2HZ 密码:zcq9

这是 打印的 dd($permission->roles);

Collection {#111 ▼
  #items: array:1 [▼
    0 => Role {#110 ▼
      #connection: null
      #table: null
      #primaryKey: "id"
      #perPage: 15
      +incrementing: true
      +timestamps: true
      #attributes: array:5 [▼
        "id" => 1
        "name" => "admin"
        "label" => "Admin"
        "created_at" => "2016-10-10 03:20:48"
        "updated_at" => "2016-10-10 03:20:48"
      ]
      #original: array:7 [▼
        "id" => 1
        "name" => "admin"
        "label" => "Admin"
        "created_at" => "2016-10-10 03:20:48"
        "updated_at" => "2016-10-10 03:20:48"
        "pivot_permission_id" => 1
        "pivot_role_id" => 1
      ]
      #relations: array:1 [▼
        "pivot" => Pivot {#109 ▶}
      ]
      #hidden: []
      #visible: []
      #appends: []
      #fillable: []
      #guarded: array:1 [▶]
      #dates: []
      #dateFormat: null
      #casts: []
      #touches: []
      #observables: []
      #with: []
      #morphClass: null
      +exists: true
      +wasRecentlyCreated: false
    }
  ]
}

额 可是我这里修改了 return true; 还是 没有出现'编辑'. 这个该如何排错呢. 在 boot里都可以打印出来.

public function hasRole($role)
    {
        
        //如果包含某一个 就说明有这个角色
        // if (is_string($role)) {
        //     return $this->roles->contains('name', $role);
        // }
        //  //如果是Collection
        // return !!$roles->intersect($this->roles->count());//是否相同 >0
        return true;
    }

老师, 我return true;之后还是没打印出来. 是因为哪里逻辑有问题吗?我打印出来

public function boot(GateContract $gate)
    {
        parent::registerPolicies($gate);
        foreach ($this->getPermissions() as $permission) {
        dd($permission->roles);
            $gate->define($permission->name,function(User $user) use ($permission){
                return $user->hasRole($permission->roles);
            });
        }
        
    }

发现是一个collection,然后程序到hasrole 该如何打印查看呢?hasrole几个intersect contains,还有一些$this->roles() 和 $role.比较的,学习感觉风中有点凌乱

老师,我跟你的代码打的,laravel-v5.2.15. 有些地方不太一样.但是我有的改好了,,就是一直没出先"编辑".视频9分43秒 修改好还是没出现

为什么突然在

foreach ($this->getPermissions() as $permission) {
            $gate->define($permission->name,function($user) use ($permission){
                return $user->hasRole($permission->roles);
            };
        }

这个 function ($user) 加了 user??视频 6分19秒