mercredi 15 février 2017

Can't reference static fields in Laravel Model's create method

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.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lR79lD
via IFTTT

Aucun commentaire:

Enregistrer un commentaire