1

我有一个像下面这样来自表单的数组:

array:4 [▼
  "login-history.view" => "true"
  "login-history.create" => "true"
  "login-history.edit" => "true"
  "login-history.delete" => "true"
]

我想像这样将它存储在数据库中:

{
"login-history.view":true, //without double qoute in value true and false.
"login-history.create":true,
"login-history.edit":true,
"login-history.delete":true
}

但是,当我保存它时,它总是保存如下:

{
"login-history.view":"true", //I want to remove double quote around true and false for every value 
"login-history.create":"true",
"login-history.edit":"true",
"login-history.delete":"true"
}

我想在没有双重引用的情况下保存记录value(true and false)。我目前只是将值保存为雄辩的价值保存

$permissions = $request->get('permissions');
$role = Sentinel::findRoleBySlug($slug); //slug is role slug ex. admin, manager, user
$role->permissions = $permissions;
$role->save()

我怎样才能实现它?

更新

我正在使用 Laravel 5.4 和 mysql 数据库,用于 ACL 的 Cartalyst Sentinel 包

4

1 回答 1

1

这是解决上述问题的蛮力方法

foreach($myArray as $key=>$value){
    $myArray[$key] = $value==='true' ? true : false;
}
于 2017-05-30T11:29:11.057 回答