我有一个类似于下面的数组来自表单:
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)
附近没有双qoute的情况下保存记录。我目前只是将值保存为雄辩值保存
$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数据库,Cartalyst Sentinel Package for ACL
答案 0 :(得分:1)
这是对上述问题的蛮力方法
foreach($myArray as $key=>$value){
$myArray[$key] = $value==='true' ? true : false;
}