John Howard

1645 经验值

教程哪一集里有涉及到toArray()?我去看看

在blade里面,列出所有的display_name,也是用这个吗?

@foreach($role as $rp)
    <p> $rp->perms()->pluck('display_name') </p>
@endforeach

使用pluck取到数据值,渲染到页面,会这样显示,如何只取到名称

["Create Posts"]

[]
    $user = Auth::user();
    $permission = $user->with('roles.perms')->get();
    return $permission->pluck('display_name');

这样就会显示NULL,用上面的方法:

     $user = Auth::user();
     $permission = $user->with('roles.perms')->get();
     return $permission->pluck('roles.perms.display_name');

也是同样的null

[
  {
    "id": 1,
    "name": "john",
    "email": "[email protected]",
    "created_at": "2016-12-19 09:24:10",
    "updated_at": "2016-12-19 09:24:10",
    "roles": [
      {
        "id": 1,
        "name": "owner",
        "display_name": "Project Owner",
        "description": "User is the owner of a given project",
        "created_at": "2016-12-19 09:20:50",
        "updated_at": "2016-12-19 09:20:50",
        "pivot": {
          "user_id": 1,
          "role_id": 1
        },
        "perms": [
          {
            "id": 1,
            "name": "create-post",
            "display_name": "Create Posts",
            "description": "create new blog posts",
            "created_at": "2016-12-19 09:27:45",
            "updated_at": "2016-12-19 09:27:45",
            "pivot": {
              "role_id": 1,
              "permission_id": 1
            }
          },
          {
            "id": 2,
            "name": "edit-user",
            "display_name": "Edit Users",
            "description": "edit existing users",
            "created_at": "2016-12-19 09:27:45",
            "updated_at": "2016-12-19 09:27:45",
            "pivot": {
              "role_id": 1,
              "permission_id": 2
            }
          }
        ]
      }
    ]
  }
]
    $user = Auth::user();
    $permission = $user->with('roles.perms')->get();
    return $permission->pluck('display_name');

这样输出会显示NULL

    $permission = $user->with('roles.permissions')->get();
    return $permission;

这样写完之后,如何获取permission的display_name的字段值?

现在获取到了,如何获取permissions的name值呢?

获取到1和2两个role的id ,如何获取对应的permission的name?

获取到1和2两个role的id ,如何获取对应的permission的name?