mercredi 8 mai 2019

Object property just absolutely refuses to unset

So, I have an Event in Laravel, which simply broadcasts an object of type Activity onto a socket channel.

Sometimes my activity is too big, so I'm trying to remove some properties from it. I've tried absolutely everything, and it removes/unsets correctly on one line, then on the next, it's back again.


    public function broadcastOn()
    {
       // Approach 1: Set projects to null
       $this->activity->activityable->projects = null;

       Log::info($this->activity->activityable->projects); // This'll be null

       // Approach 2: Unset
       unset($this->activity->activityable->projects);

       Log::info($this->activity->activityable->projects); // This'll be undefined

       // Approach 3: Overwrite the whole activity
       $activity = $this->activity;

       unset($activity->activityable->projects);
       Log::info(json_encode($activity)); // Projects isn't in this one

       $this->activity = $activity;

       // Tada! Projects is magically back! Doesn't matter what ya do!
       Log::info(json_encode($this->activity));

       return new PresenceChannel('account_'.$this->activity->account_id);
    }


Does anyone know what the hell could be doing this? I've tried to json_encode then json_decode the entire object as well, and it still just decides to return every time...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire