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

保存时从数组值中删除双引号 - 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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?