Laravel create a dynamic schedule table
<p>I have a hospital table and schedule table, and i want to create a schedule table html using these table</p>

<pre><code>+----+--------------+
| id |     name     |
+----+--------------+
|  1 |  hospital a  |
|  2 |  hospital b  |
+----+--------------+

+-----+---------+--------+---------------+
| day |  start  |   end  |  hospital_id  |
+-----+---------+--------+---------------+
| mon |  10:00  |  14:00 |       1       |
| tue |  15:00  |  20:00 |       1       |
| wed |  14:00  |  19:00 |       2       |
| fri |  10:00  |  15:00 |       2       |
+-----+---------+--------+---------------+
</code></pre>

<p>the problem is the schedule time didn't align to the correct <code>&lt;th&gt;</code><br>
What i need:</p>

<pre><code>+-------+------+--------+-------+-------+-------+------+
| mon   |  tue  |  wed  |  thu  |  fri  |  sat  |  sun |
+------------------------------------------------------+
|                     hospital a                       |
+-------+-------+-------+-------+-------+-------+------+
| 10:00 | 15:00 |       |       |       |       |      |
|   -   |   -   |       |       |       |       |      |
| 14:00 | 20:00 |       |       |       |       |      |
+-------+-------+-------+-------+-------+-------+------+
|                     hospital b                       |
+-------+-------+-------+-------+-------+-------+------+
|       |       | 14:00 |       | 10:00 |       |      |
|       |       |   -   |       |   -   |       |      |
|       |       | 19:00 |       | 15:00 |       |      |
+-------+-------+-------+-------+-------+-------+------+
</code></pre>

<p>but it become like this</p>

<pre><code>+-------+-------+-------+-------+-------+-------+------+
| mon   |  tue  |  wed  |  thu  |  fri  |  sat  |  sun |
+------------------------------------------------------+
|                     hospital a                       |
+-------+------+--------+-------+-------+-------+------+
| 10:00 | 15:00 |       |       |       |       |      |
|   -   |   -   |       |       |       |       |      |
| 14:00 | 20:00 |       |       |       |       |      |
+-------+-------+-------+-------+-------+-------+------+
|                     hospital b                       |
+-------+-------+-------+-------+-------+-------+------+
| 14:00 | 10:00 |       |       |       |       |      |
|   -   |   -   |       |       |       |       |      |
| 19:00 | 15:00 |       |       |       |       |      |
+-------+-------+-------+-------+-------+-------+------+
</code></pre>

<p>this is my .blade.php script</p>

<pre><code>&lt;table class="table"&gt;
    &lt;thead&gt;
       &lt;tr&gt;
           &lt;td class="text-center"&gt;mon&lt;/td&gt;
           &lt;td class="text-center"&gt;tue&lt;/td&gt;
           &lt;td class="text-center"&gt;wed&lt;/td&gt;
           &lt;td class="text-center"&gt;thu&lt;/td&gt;
           &lt;td class="text-center"&gt;fri&lt;/td&gt;
           &lt;td class="text-center"&gt;sat&lt;/td&gt;
           &lt;td class="text-center"&gt;sun&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
    @foreach($hospital as $hos)
        &lt;tr&gt;
            &lt;td class="text-center _b" colspan="7"&gt;{{$hos-&gt;name}}&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
        @foreach($schedule-&gt;where('hospital_id', $hos-&gt;id) as $sch)
        @if($sch-&gt;day == 'mon')
            &lt;td class="text-center"&gt;
                &lt;div class="jam"&gt;{{Carbon::parse($sch-&gt;start_time)-&gt;format('H:i')}}&lt;/div&gt;
                &lt;div class="jam active"&gt;s/d&lt;/div&gt;
                &lt;div class="jam"&gt;{{Carbon::parse($sch-&gt;end_time)-&gt;format('H:i')}}&lt;/div&gt;
            &lt;/td&gt;
            @endif
            @if($sch-&gt;day == 'tue')
            &lt;td class="text-center"&gt;
                &lt;div class="jam"&gt;{{Carbon::parse($sch-&gt;start_time)-&gt;format('H:i')}}&lt;/div&gt;
                &lt;div class="jam"&gt;s/d&lt;/div&gt;
                &lt;div class="jam"&gt;{{Carbon::parse($sch-&gt;end_time)-&gt;format('H:i')}}&lt;/div&gt;
            &lt;/td&gt;
            @endif
            @if($sch-&gt;day == 'wed')
            &lt;td class="text-center"&gt;
                &lt;div class="jam"&gt;{{Carbon::parse($sch-&gt;start_time)-&gt;format('H:i')}}&lt;/div&gt;
                &lt;div class="jam"&gt;s/d&lt;/div&gt;
                &lt;div class="jam"&gt;{{Carbon::parse($sch-&gt;end_time)-&gt;format('H:i')}}&lt;/div&gt;
            &lt;/td&gt;
            @endif
            @if($sch-&gt;day == 'thu')
                &lt;td class="text-center"&gt;
                    &lt;div class="jam"&gt;{{Carbon::parse($sch-&gt;start_time)-&gt;format('H:i')}}&lt;/div&gt;
                    &lt;div class="jam"&gt;s/d&lt;/div&gt;
                    &lt;div class="jam"&gt;{{Carbon::parse($sch-&gt;end_time)-&gt;format('H:i')}}&lt;/div&gt;
                &lt;/td&gt;
                @endif
                @if($sch-&gt;day == 'fri')
                &lt;td class="text-center"&gt;
                    &lt;div class="jam"&gt;{{Carbon::parse($sch-&gt;start_time)-&gt;format('H:i')}}&lt;/div&gt;
                    &lt;div class="jam"&gt;s/d&lt;/div&gt;
                    &lt;div class="jam"&gt;{{Carbon::parse($sch-&gt;end_time)-&gt;format('H:i')}}&lt;/div&gt;
                &lt;/td&gt;
                @endif
                @if($sch-&gt;day == 'sat')
                &lt;td class="text-center"&gt;
                    &lt;div class="jam"&gt;{{Carbon::parse($sch-&gt;start_time)-&gt;format('H:i')}}&lt;/div&gt;
                    &lt;div class="jam active"&gt;s/d&lt;/div&gt;
                    &lt;div class="jam"&gt;{{Carbon::parse($sch-&gt;end_time)-&gt;format('H:i')}}&lt;/div&gt;
                &lt;/td&gt;
                @endif
                @if($sch-&gt;day == 'sun')
                &lt;td class="text-center"&gt;
                    &lt;div class="jam"&gt;{{Carbon::parse($sch-&gt;start_time)-&gt;format('H:i')}}&lt;/div&gt;
                    &lt;div class="jam"&gt;s/d&lt;/div&gt;
                    &lt;div class="jam"&gt;{{Carbon::parse($sch-&gt;end_time)-&gt;format('H:i')}}&lt;/div&gt;
                &lt;/td&gt;
                @endif
                @endforeach
            &lt;/tr&gt;
            @endforeach
        &lt;/tbody&gt;
    &lt;/table&gt;
&lt;/table&gt;
</code></pre>

<p>this is happen because the <code>&lt;td&gt;&lt;/td&gt;</code> will not created when the <code>if</code> condition doesn't meet. but when I try to move <code>if</code> inside the <code>td</code> the table looks more terrible</p>