Support the ongoing development of →
Laravel Eloquent
Last updated 1 year ago.


I'm assuming this is an object, right?

You could try defining the variables outside the constructor first. So like this:

class Something
    public $name;
    public $zip_code;
    public $phone_number;

    public method __construct()
        $this->name = "John";
        $this->zip_code = "abcd12";
        $this->phone_number = "0123456789";

    public method getValues()
        // just checking:
        dump ($this->name);

I think that should work.

Now, if it's actually a controller, it might not work that way. But then again, I can't see any use case for that? If the values are actually static, define them as config variables. If they're variable, they probably come from the request and don't need to be set in the constructor.


Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.