I have a Laravel model acl_groups
that has a JSON column inherits
. What should I do, the "laravel way" to query the inherited groups when checking if a group can do something? The rights are stored in another JSON column, allow/deny so I can just do a in_array
to check a single group if they have access.
Laravel的Eloquent表与父母“继承”
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- dongyinpan9284 2016-02-01 15:53关注
On your
model
you can set agetter
public function getInheritsAttribute($v) { return $v ? json_decode($v, true) : []; }
OR if you dont want a getter you can try a pseudo getter
public function getPseudoAttribute() { return $this->inherits ? json_decode($this->inherits, true) : []; }
Kind of maybe did mistake on second one.
And on other model the same thing so when you call $item->inherits = you will get an
array
First you may try to prepare the array like removing same keys or valuesand after just check
if (array_key_exists('thing_to_check', $item->inherits)) { return true; }
This is not a working code, it is just an idea how you can do you. Take a look at
Cartalyst Sentinel
how they check the permissions for groups and users.解决 无用评论 打赏 举报
悬赏问题
- ¥30 这是哪个作者做的宝宝起名网站
- ¥60 版本过低apk如何修改可以兼容新的安卓系统
- ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
- ¥50 有数据,怎么建立模型求影响全要素生产率的因素
- ¥50 有数据,怎么用matlab求全要素生产率
- ¥15 TI的insta-spin例程
- ¥15 完成下列问题完成下列问题
- ¥15 C#算法问题, 不知道怎么处理这个数据的转换
- ¥15 YoloV5 第三方库的版本对照问题
- ¥15 请完成下列相关问题!