dimanche 30 août 2015

If inside foreach not working as expected in Laravel

My if is not displaying as expected in Laravel.

This is in the model:

    public function getTags()
{
    $tags = [];
    foreach (Config::get('products.tags') as $tag) {
        if ($this->$tag)
            $tags[] = $this->getLabel($tag);
    }
    if ($this->extra_tag)
        $tags[] = $this->extra_tag;

    return $tags;
}

And this in the view:

    @foreach($product->getTags() as $tag)
        @if($this->$tag='bespoke shape')
            <div class="tag-purple">
        @else
            <div class="tag-grey">
        @endif
        {{$tag}}</div>
    @endforeach

I would expect to see the tag 'bespoke shape' to have purple background and other tags to have grey background. Unfortunately, they all have purple background. The names of the tags, however, are displayed correctly.

Do you have any ideas of what I can do to make it work?

Aucun commentaire:

Enregistrer un commentaire