php-casbin / laravel-authz

An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.
Apache License 2.0
272 stars 46 forks source link

ABAC model 情况下报错 #33

Closed guoliang1994 closed 2 years ago

guoliang1994 commented 2 years ago

Unable to get property "Owner" of non-object "r_obj".

下面是 model 定义

[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = r.sub == r.obj.Owner
  $canVisit = Enforcer::enforce("alice",  "{Owner: 'alice'}",  "read");
guoliang1994 commented 2 years ago

enforece 支持对象,或者数组的形式传入,而不是字符串

  $class = new stdClass();  // 新建一个stdClass
    $class->Owner = "alice";
    $canVisit = Enforcer::enforce("alice",$class, "read");  // 传入对象而非字符串 json 对象
    dd($canVisit);