remove double quote from array value while saving - php

1k views Asked by At

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

There are 1 answers

5
George Dryser On BEST ANSWER

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

foreach($myArray as $key=>$value){
    $myArray[$key] = $value==='true' ? true : false;
}