Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

babo's avatar
Level 1

How to make red color in date range for holidays in admin input in laravel

Hi everyone. I want to create a date range that is selected by the user if that date has been added to the company_holiday table it will be red. when I return the result of $holiday data from 2022-04-04 I already got it. At the bottom I've added @if ($holiday == $range) data-fill-color="DB4437" style="background-color:#DB4437; color: #fff" @endif so I give a red background but my code is not correct, the view is still not red, is there something wrong with my code, anyone please help me.

my code in index.blade.php

//to get date range from query start_date end_date
 @php
      $start_date = \Carbon\Carbon::parse(request()->query('start_date '))->format('Y-m-d');
      $end_date = \Carbon\Carbon::parse(request()->query('end_date'))->format('Y-m-d');
                            
      $dateRangePeriod = \Carbon\CarbonPeriod::create($start_date , $end_date);
      $dateRange = [];
      foreach ($dateRangePeriod as $key => $date) {
            $dateRange[] = $date->format('Y-m-d');
      }
 @endphp

//retrieve data from database from table company holiday

 @php
       $holiday = [];
       foreach ($company_holiday as $key => $comp_hol) {
            $holiday[] = $comp_hol->where('company_id', Auth::user()->company_id)->select('date')->get();
       }
@endphp

//process whether in the range there are dates listed in the company holiday table

 @foreach ($dateRange as $key => $range)
      @if ($key == 0)
          <th colspan="2" data-b-a-s="thin" data-b-a-c="00000000" data-a-h="center" data-a-v="center">#</th>
      @endif
         <th data-b-a-s="thin" data-b-a-c="00000000" data-a-h="center" data-a-v="center" colspan="3" class="text-center" 
  
      @if ($holiday == $range) data-fill-color="DB4437" style="background-color:#DB4437; color: #fff" @endif >{{ $range }}</th>
@endforeach

0 likes
1 reply
sr57's avatar

a typo at the end of this line

         <th data-b-a-s="thin" data-b-a-c="00000000" data-a-h="center" data-a-v="center" colspan="3" class="text-center"

missing >

Please or to participate in this conversation.