dimanche 2 juillet 2017

Set attribute from 2 sources in laravel 5?

I set my "slug" value in laravel so:

public function setTitleAttribute($value)
    {
        $this->attributes['title'] = $value;
        $this->attributes['slug'] = str_slug($value);
    }

This method works, but much elements at the moment has the same name and same generated slug, so I want to add additional content to slug, how can I do it? Can I do something like

public function setTitlePackAttribute($value, $key)
{
    $this->attributes['title'] = $value;
    $this->attributes['pack'] = $key;
    $this->attributes['slug'] = str_slug($value . $key);
}

I want to generate slug from more sources...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire