6 months ago

How to re-construct a Class in single process?

Posted 6 months ago by muzafferdede

Hi, Is there any way i can reconstruct my controller classes after some method calls?

Because i am doing some logic in "while" loop and i need to re instance some classes to update its properties during same process.

for now i am doing it with

    public function status()
        return $this->successful($this->device);
public function register()
        $device = Device::updateOrCreate(
                'serial_number' => $this->request->serial_number,
                'name' => $this->request->serial_number,
                'type' => $this->request->type,
                'properties' => $this->request->properties,

        return $device->save() ? $this->successful($device) : $this->failed(15);

    public function activate()
        $device = Device::whereActivationCode($this->request->activation_code)

        if (!$device) {
            return $this->failed(9);

        if ($device->activated) {
            return $this->failed(10);

        $store = Store::whereUid($this->request->uid)->first() ?? $device->store;
        if (!$store) {
            return $this->failed(0);

        $device->activated = now();
        $device->api_token = Str::uuid();

        return $this->successful($device);

as you can see, all my methods has to re-construct to renew its properties. I can't kill the process because i am listening a socket for new events. Because of this, application only can boot 1 time. I am not sure how can i renew the existing instances in the application container. I would like to use service provider to achieve it. And update the singleton anytime new events causes.

any advice? Thanks.

Please sign in or create an account to participate in this conversation.