Rosh
Rosh

Reputation: 491

Changing background color not working when a condition is checked inside table row

Here i have a 'work' array (generating from excel file) which has values employee_id(here id),projects ands hours.I also have another array 'employees' which has all the employees in my database. Here i need to check if the employee exist in my database by comparing with the ids. If employee exists, i need to change the background color of the table row.I tried this method but not working, please help .

@foreach($val['work'] as $k3=> $val3)
    @if(isset($val3['hours']) && isset($val3['projects']))                                
        <tr @foreach($employees as $employee) @if($employee->emp_id ==$val3['id'][1]) style="background-color:#ffe1df;" @endif @endforeach>
            <td>{{$val3['id'][1]}}</td>
            <td>{{$val3['name'][2]}}</td>
        </tr>
    @endif
@endforeach 

Upvotes: 1

Views: 59

Answers (1)

Mik_ko
Mik_ko

Reputation: 134

Try setting a flag value :

@foreach($val['work'] as $k3=> $val3)
    @if(isset($val3['hours']) && isset($val3['projects']))
        @php $flag=0; @endphp
        @foreach($employees as $employee) @if($employee->emp_id == $val3['id'][1])  @php $flag=1 @endphp @endif @endforeach
        <tr @if($flag==0) style="background-color:#ffe1df;" @endif>
            <td>{{$val3['id'][1]}}</td>
            <td>{{$val3['name'][2]}}</td>
        </tr>
    @endif 
@endforeach

Upvotes: 1

Related Questions