Dynamically change text color based on a value retrived from database

I am working with PHP/Laravel. I query my TaskType model to retrieve specific key & values. I then proceed to assign a color based on the retrieved value. For example, if the value is START, i assign this value ‘colorStart’, which is just a variable that retrieves the associated color of my ‘START’ value.

public function index()
        $eventStartData = TaskType::all()->where('event', 'START');
        $eventStopData = TaskType::all()->where('event', 'STOP');
        $eventReportData = TaskType::all()->where('event', 'REPORT');
        $colorStart = TaskType::all()->where('colors', '#4f5705');
        $colorStop = TaskType::all()->where('colors', '#f43f1a');
        $colorReport = TaskType::all()->where('colors', '#8acae7');
        $color = '' ;
            $color = $colorStart ;            
            $color = $colorStop ;
            $color = $colorReport ;

this is table-display html :

        <div class="row" style="margin-top: 210px;">
            <table class="table" id="">
                        <th>Program Time</th>
                <tbody >
                @foreach($welcome as $key => $data)

I am stuck and curious to know how i can dynamically change my <td {{$data->event}} element based on the colors I have defined in my index function ?

Source: CSS – Stack Overflow

September 3, 2021
Category : News
Tags: css | laravel

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.