Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notice: Indirect modification of overloaded element of builder\Database\Collections\Collection has no effect #4

Open
tamedevelopers opened this issue May 3, 2023 · 0 comments
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers wontfix This will not be worked on

Comments

@tamedevelopers
Copy link
Owner

When you see this Error:
Nothing wrong and it's because your trying to change the collection data value without converting to an array.

$rows = $db->table('tb_user')->where('user_id', $user_id)->get();

// You cannot direct change the collection data
// Instead you can use a new variable name
// or Convert to an array first before loop

foreach($rows as $key => $value){
$rows[$key]['address'] = json_decode($value['address'], TRUE);
}

Example 1:
$rows = $db->table('tb_user')->get()->toArray();

// Immediately you convert data to array, This will not be a collection instance anymore
// It becomes an array
foreach($rows as $key => $value){
$rows[$key]['address'] = $value['address'];
}

Example 2:
$rows = $db->table('tb_user')->get(;

$data = [];
foreach($rows as $key => $value){
$data[$key]['address'] = $value['address'];
}

@tamedevelopers tamedevelopers added documentation Improvements or additions to documentation good first issue Good for newcomers wontfix This will not be worked on labels May 3, 2023
@tamedevelopers tamedevelopers pinned this issue May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant