2

I have recently started learning Laravel and I'm trying to reference a static field, in this case $myUrls, in my Model's create method. This is what I'm trying to do but I keep getting the error:

Undefined variable: myUrls

class myclass extends mySuperclass
{
 public static $myUrls= [ some data]

 public static function create( array $attributes = [] )
{

    $newObj = parent::create($attributes);
    $newObj->buildUrlLookups($newObj);
    return $newObj;
}

private function buildUrlLookups($newObj)
{  
    foreach ($newObj->$myUrls as $u) 
    {
    //some code
    }
}

I have also tried it with $this->myUrls and just $myUrls but non works.

3
  • myUrls isn't a attribute of mySuperclass object. Commented Feb 15, 2017 at 16:55
  • @FelippeDuarte you are right. Is there anyway I can reference it? Commented Feb 15, 2017 at 16:56
  • 1
    Directly, no. But in foreach you could use foreach(self::myUrls as $u). Look at Jake answer. Commented Feb 15, 2017 at 17:00

1 Answer 1

3

try

 foreach (self::$myUrls as $u) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.