php - Laravel Question: How to exclude values from @foreach inside @for

This is my problem, I want to create a buttons for time, where my users could select 1 hour, I use a for loop to show the time in buttons from 9:00 to 18:00, but I have a table, in this tables I schedule the appointments, and I have a column called "time" I want to check if the time exists on my table, the show me this time on red, and if doesnt exist on my table, show me a blue button.

    @for($x = 9; $x <= 18; $x++)
        @php
        $time = $x.":00:00";  //To convert the number to time
        @endphp
    @foreach($Dates as $Date)
    @if($Date->time == $time) // To check if the time exists o table
    @if($Date->date == $datesaved) // To check if the day and month do it match
      <input type="text" class="btn btn-danger  w-100" value="{{$Date->time}}"><br/><br/>
    @endif
    @endif
    @endforeach
      <input type="text" class="btn btn-primary  w-100" value="{{$x}}"><br/><br/>
    @endfor

On the attached image, you could see that I get the buttons on blue and red as I want, but I have twice the 10 am and the 12 pm, How can I exclude this in my @for and @foreach?

enter image description here

Alberto

Answer

Solution:

I solved changing for

 @if($Cita->where('time','=',$time)->where('date','=',$datesaved)->count() > 0)

Source