基于用户隐私设置进行授权laravel

基于用户隐私设置进行授权laravel,laravel,Laravel,我有一个表users和一个json列privacy,其中包含许多设置 用户 - id - privacy JSON 某些隐私设置具有布尔值,而其他设置可能具有字符串值(多个值) 例如,设置“显示生日”可以有值true或false { “show_birthday” : true } 设置show_profile可以具有以下值 每个人 没有人 成员(注册用户) 跟踪(我跟踪的用户) 我想要两个函数 根据设置值返回true或false的函数 一种函数,它根据设置的值返回true或引发异常

我有一个表
users
和一个
json
privacy
,其中包含许多设置

用户

- id 
- privacy JSON
某些隐私设置具有布尔值,而其他设置可能具有字符串值(多个值)

例如,设置“显示生日”可以有值truefalse

{ “show_birthday” : true }
设置show_profile可以具有以下值

  • 每个人
  • 没有人
  • 成员(注册用户)
  • 跟踪(我跟踪的用户)
我想要两个函数

  • 根据设置值返回true或false的函数
  • 一种函数,它根据设置的值返回true或引发异常
例如,如果设置show_profile等于members

{ “show_profile” : “members” }

// return true if the visitor is authenticated or false if not 
$user->allows(‘show_profile’)

// return true if the visitor is authenticated, otherwise throw exception 
$user->authorizes(‘show_profile’)
如果设置show_profile等于following

{ “show_profile” : “following” }

// return true if the user is following the visitor or false if not 
$user->allows(‘show_profile’)

// return true if the user is following the visitor, otherwise throw exception 
$user->authorizes(‘show_profile’)