dsm17496
2017-05-30 11:22
采纳率: 100%
浏览 127
已采纳

保存时从数组值中删除双引号 - php

I have an array like below which comes from form:

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

I want to store it in database like this:

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

But, when I saved it, it always saves like below:

{
"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"
}

I want to save the record without double qoute around value(true and false). I currently simply saving the values as in eloquent value saving

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

How can I achieve it?

Update

I am using Laravel 5.4 and mysql database, Cartalyst Sentinel Package for ACL

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duai3681 2017-05-30 11:29
    已采纳

    this is a brute force approach to the problem as defined above

    foreach($myArray as $key=>$value){
        $myArray[$key] = $value==='true' ? true : false;
    }
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题