Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

puggahz's avatar

Indirect modification of overloaded element

I am actually using moloquent for this, but the usage has worked exactly like eloquent to this point. I am attempting to assign the user_name (retrieved from the TwitterAccount collection) to the tweets that are being retrieved by my query (in the Tweets collection) Not sure what exactly I am doing wrong here but I recieve this error: Indirect modification of overloaded element of App\Tweet has no effect

function getUserName($tweets)
{
    foreach ($tweets as $tweet) {


        $user_id = $tweet[ 'user' ][ 'id_str' ];

        $account = TwitterAccount ::where('id_str', $user_id)->get()->first();
        $t = Tweet ::where('id_str', $tweet['id_str']) -> get() -> first();

        $t['user']['screen_name'] = $account['screen_name'];
        $t->save();
    }

}

Any thoughts would be greatly appreciated.

0 likes
2 replies
lostdreamer_nl's avatar
Level 53

do you have a setUserAttribute on the Tweet model by any chance?

I usually get this message when I have a set...Attribute expecting an array, and then trying to 'directly modify' this array.

It will work if you do something like:

$user = $t->user;
$user['screen_name'] = $account['screen_name'];
$t->user = $user;
$t->save();
4 likes
puggahz's avatar

Awesome, that worked! Thanks for the assist!

Please or to participate in this conversation.