Skip to content

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

Description

@tamedevelopers

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'];
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomerswontfixThis will not be worked on

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions