vendredi 19 juin 2020

Returning Optional Values based on Database Value

I'm trying to return a SVG based on the value 1,2 or 3 from my database column called foo_options.

  • IF 1 return Green SVG
  • IF 2 return Orange SVG
  • IF 3 return Red SVG

foo_options has the value of 3 in the database. So the SVG should be Red.

Here is what I have in my Model:

    public function getOptionValueAttribute(){
        if ('1') {
            return '<svg>Green</svg>';
        }elseif ('2') {
            return '<svg>Orange</svg>';
        }elseif ('3') {
            return '<svg>Red</svg>';
        } else {
            return '';
        }
    }

Then my logic is:

if($bar->barDetail->some_options = '1' || $bar->barDetail->some_options = '2' || $bar->barDetail->some_options = '3')
{
    dd($bar->barDetail->optionValue);
}

With the above logic, GREEN (1) is always returned.

Any help to return Red would be much appreciated.

Aucun commentaire:

Enregistrer un commentaire