0

I've already looked at the following, but haven't been able to solve my problem: - "Indirect modification of overloaded element of SplFixedArray has no effect"

I'm using Laravel 4 with Eloquent. To access a user in the database, I create the following query.

$user = User::find(Auth::id())->first();

The $user object is represented as the following.

{
  "_id": {
    "$id": "56b50fe08525cd0d3e9d8dc4"
  },
  ...
  "splits": {
    "owned": [],
    ...
  },
  ...
}

I'm currently trying to append a string to the splits->owned array, but I'm having the error "Indirect modification of overloaded property User::$splits has no effect". The error is raised on the third line below.

private function generateUserSplits($split) {
    $user = User::find(Auth::id());
    array_push($user->$splits->$owned, $split->id);
    $user->save();
}

$split->id contains a string of characters similar to "56b50fe08525cd0d3e9d8dc4". I've already had a browse around stack overflow for similar answers, and as of yet have had no success.

If anyone could provide some help, it would be greatly appreciated. Thanks

Community
  • 1
  • 1
  • Are u sure $split array is defined in your User Model?? – Peyman.H Feb 05 '16 at 21:57
  • $split here is the argument to the function. $splits is in the json representation of the model above. In my UserController, this code is executed when a User is created ` $splits = array( "owned" => array(), "contributed" => array(), "favourites" => array() ); $user->splits = $splits; ` – Struan McDonough Feb 06 '16 at 10:11

0 Answers0