Search code examples
phpcsslaravelhtml-tablecell

Laravel - Illegal string offset


I try to color table cell in laravel based on cell content but i keep getting this error:

"Illegal string offset 'Disponible' (View: C:\Users\RAYLAN\Documents\CRMSAV\resources\views\ pagination_data.blade.php)
(View: C:\Users\RAYLAN\Documents\CRMSAV\re..."

This is my code:

@foreach($data as $row)
<tr>
 <td>{{ $row->ID_Piece }}</td>
 <td>{{ $row->Designation }}</td>
 <td style="background-color: {{ $row->Status['Disponible'] }}">
        {{ $row->Status }}
</td>
</tr>
{{$row->Status = array('Disponible' => '#FF0', 'N' => '#F0F')}}
@endforeach
<tr>
 <td colspan="3" align="center">
  {!! $data->links() !!}
 </td>
</tr>

Solution

  • I decided to do it with Jquery, here is the working solution :

    @foreach($data as $row)
     <tr>
     <td>{{ $row->ID_Piece }}</td>
     <td>{{ $row->Designation }}</td>
     <td id="status">{{ $row->Status }}</td>
    </tr>
    @endforeach
    <tr>
     <td colspan="3" align="center">
      {!! $data->links() !!}
     </td>
    </tr>
    
    <script type="text/javascript">
    
            $(document).ready(function(){
                $('#status').each(function(){
                    if ($(this).text() == 'N') {
                        $(this).css('background-color','#f00');
                    }
                });
            });
    
    </script>