Laravel在刀片中旋转显示很多对很多

时间:2019-05-20 17:26:16

标签: laravel eloquent laravel-blade

背景

我有一个带有药物的数据透视表,患者具有数据透视元素的日期,时间,给定,给定和锁定。 示例:

id       medication_id          patient_id         Day      time      given 
1         1 (MED X)             1 (Patient X)    Yesterday  0900        1
2         1 (MED X)             1 (Patient X)    Yesterday  1200        1
3         1 (MED X)             1 (Patient X)    Today      0900        0
4         2 (MED Y)             1 (Patient X)    Tomorrow   1200        0
5         2 (MED Y)             1 (Patient X)    Yesterday  0900        1
6         1 (MED X)             2 (Patient Y)    Yesterday  1200        1
7         1 (MED X)             2 (Patient Y)    Yesterday  0900        1
8         3 (MED Z)             2 (Patient Y)    Yesterday  1200        0

患者可以在同一天内多次服用相同的药物。假设患者X昨天在0900和1200拥有Med X,今天在0900,但明天没有。

查看分配给患者X的所有药物

$assignedMeds = $patient->medication()->get();

并将其传递到视图中。

我现在拥有的是

@if(isset($assignedMeds))
    <div class="card-body">
        <table class="table table-hover">
            <tbody>
                <tr>
                    <th>Name</th>
                    <th>Yesterday</th>
                    <th>Today</th>
                    <th>Tomorrow</th>
                </tr>
                @foreach($assignedMeds as $assignedMed)
                    <tr>
                        <td>{{$assignedMed->name}}</td>
                        <td>
                            @if(($assignedMed->pivot->day) == 'yesterday')
                                @if($assignedMed->pivot->given)
                                    <i class="fas fa-check green"></i>
                                    <strike>{{$assignedMed->pivot->time}}</strike>
                                    <em>{{$assignedMed->pivot->givenby}}</em>
                                @else
                                    {{$assignedMed->pivot->time}}
                                @endif
                            @endif
                        </td>
                        <td>
                            @if(($assignedMed->pivot->day) == 'today')
                                @if($assignedMed->pivot->given)
                                    <i class="fas fa-check green"></i>
                                    <strike>{{$assignedMed->pivot->time}}</strike>
                                    <em>{{$assignedMed->pivot->givenby}}</em>
                                @else
                                    <form method="post" action="/mar/{{$assignedMed->id}}">
                                        @csrf
                                        @method('PATCH')
                                        <input hidden name="givenby" id="givenby" value="1">
                                        <button>{{$assignedMed->pivot->time}}</button>
                                    </form>
                                @endif
                            @endif
                        </td>
                        <td>
                            @if(($assignedMed->pivot->day) == 'tomorrow')
                                {{$assignedMed->pivot->time}}
                            @endif
                        </td>
                    </tr>
                @endforeach
            </tbody>
        </table>
    </div>
@endif

它给了我

Medication Name        Yesterday        Today         Tomorrow 
    Med X              0900 Given      
    Med X                                0900
    Med X              1200 Given
    Med Y              0900 Given  
    Med Y                                                0900

我在寻找什么

我想要得到的是一次显示药物名称并显示其中的时间。

患者X的示例

Medication Name        Yesterday        Today         Tomorrow 
Med X                   0900 Given      0900
                        1200 Given
Med Y                   0900 Given                     0900

1 个答案:

答案 0 :(得分:1)

您可以在Include/pyhash.h中使用 <html> <head> <style> .form-wrapper { display:flex; justify-content: center; margin: 2em 0px; } .field{ display:block; width:400px; border:1px solid green; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; border-top-left-radius: 10px; border-top-right-radius: 10px; } #input1 { width:100%; border:0px; border-top:0px solid red; border-top-left-radius: 10px; border-top-right-radius: 10px; } #input2 { width:100%; border:0px; border-top:1px solid red; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px;} input { min-height:80px; height:auto; padding: 3em; } input::placeholder { color: gray; } </style> </head> <body> <form> <div class="field"> <input id="input1" type="text" placeholder="Enter Your Email Adress"/> <br> <input id="input2" type="text" placeholder="Enter Your Password"/> </div> </form> </body> </html> groupBy() Collection methods。它应该最终看起来像这样。

where()