我正在开发用于数字签名的Laravel PHP应用程序,
当前在我的一个刀片文件中,我有一个foreach,旨在一次添加所有文档(在自己的刀片文件中)
但是我有一个问题,在循环的第一次迭代之后,我的if语句旨在仅过滤出定义了签名者的文档(这样,不必签名的用户就不会看到文档)对于($ document-> responsible_signer == $ user-> id && $ document-> packet-> live)等情况返回true,其中$ document-> responsible_signer == 9和$ user-> id == 2
它在第一次迭代中工作正常,但在第二次迭代中效果不佳。
我简化了代码以降低其复杂性,并尝试移动首先调用的字段而结果没有变化,这表明它发生在第一次迭代之后,而不是因为if语句很时髦
dragexit
预期结果是仅显示文档作为示例
$ document-> witness_signer == $ user-> id
如果为真,则返回文档,否则返回
这是转储,集合中的第一个文档设置了信息,第二个文档没有设置信息,两个都被显示,但是第一个文档显示了两次
<div class="row justify-content-center">
@foreach($facilityDocs->where('completed_at', null) as $document)
@if($document->user_id == $user->id && $document->packet->live)
<div class="col-4 my-3">
@include('patient._document_card', ['document' => $document])
</div>
@endif
@if($document->responsible_signer == $user->id && $document->packet->live)
<div class="col-4 my-3">
@include('patient._document_card', ['document' => $document])
</div>
@endif
@if($document->responsible_two_signer == $user->id && $document->packet->live)
<div class="col-4 my-3">
@include('patient._document_card', ['document' => $document])
</div>
@endif
@if($document->witness_signer == $user->id && $document->packet->live)
<div class="col-4 my-3">
@include('patient._document_card', ['document' => $document])
</div>
@endif
@if($document->community_signer == $user->current_facility_id && $document->packet->live)
<div class="col-4 my-3">
@include('patient._document_card', ['document' => $document])
</div>
@endif
@endforeach
</div>
这是我生成文件的控制器的一部分
Collection {#425 ▼
#items: array:14 [▼
0 => Document {#391 ▶}
1 => Document {#392 ▶}
2 => Document {#393 ▶}
3 => Document {#394 ▶}
4 => Document {#395 ▶}
5 => Document {#396 ▶}
6 => Document {#397 ▶}
7 => Document {#398 ▶}
8 => Document {#399 ▶}
9 => Document {#400 ▼
#dates: array:1 [▶]
#connection: "mysql"
#table: "documents"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:22 [▼
"id" => 10
"user_id" => 1
"visit_id" => 1
"packet_id" => 17
"completed_at" => null
"created_at" => "2019-07-19 17:55:32"
"updated_at" => "2019-07-19 17:56:29"
"completed_by_patient" => 1
"completed_by_responsible" => 0
"completed_by_witness" => 0
"completed_by_community" => 0
"completed_by_responsible_two" => 0
"completed_by_patient_id" => 1
"completed_by_responsible_id" => 0
"completed_by_responsible_two_id" => 0
"completed_by_witness_id" => 0
"completed_by_community_id" => 0
"facility_id" => 1
"responsible_signer" => 2
"responsible_two_signer" => 9
"witness_signer" => 10
"community_signer" => null
]
#original: array:22 [▼
"id" => 10
"user_id" => 1
"visit_id" => 1
"packet_id" => 17
"completed_at" => null
"created_at" => "2019-07-19 17:55:32"
"updated_at" => "2019-07-19 17:56:29"
"completed_by_patient" => 1
"completed_by_responsible" => 0
"completed_by_witness" => 0
"completed_by_community" => 0
"completed_by_responsible_two" => 0
"completed_by_patient_id" => 1
"completed_by_responsible_id" => 0
"completed_by_responsible_two_id" => 0
"completed_by_witness_id" => 0
"completed_by_community_id" => 0
"facility_id" => 1
"responsible_signer" => 2
"responsible_two_signer" => 9
"witness_signer" => 10
"community_signer" => null
]
#changes: []
#casts: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:1 [▶]
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
#guarded: array:1 [▶]
}
10 => Document {#401 ▶}
11 => Document {#402 ▶}
12 => Document {#403 ▶}
13 => Document {#404 ▼
#dates: array:1 [▶]
#connection: "mysql"
#table: "documents"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:22 [▼
"id" => 14
"user_id" => 1
"visit_id" => 1
"packet_id" => 21
"completed_at" => null
"created_at" => "2019-07-19 18:05:17"
"updated_at" => "2019-07-19 18:05:17"
"completed_by_patient" => 0
"completed_by_responsible" => 0
"completed_by_witness" => 0
"completed_by_community" => 0
"completed_by_responsible_two" => 0
"completed_by_patient_id" => 0
"completed_by_responsible_id" => 0
"completed_by_responsible_two_id" => 0
"completed_by_witness_id" => 0
"completed_by_community_id" => 0
"facility_id" => 1
"responsible_signer" => null
"responsible_two_signer" => null
"witness_signer" => null
"community_signer" => null
]
#original: array:22 [▼
"id" => 14
"user_id" => 1
"visit_id" => 1
"packet_id" => 21
"completed_at" => null
"created_at" => "2019-07-19 18:05:17"
"updated_at" => "2019-07-19 18:05:17"
"completed_by_patient" => 0
"completed_by_responsible" => 0
"completed_by_witness" => 0
"completed_by_community" => 0
"completed_by_responsible_two" => 0
"completed_by_patient_id" => 0
"completed_by_responsible_id" => 0
"completed_by_responsible_two_id" => 0
"completed_by_witness_id" => 0
"completed_by_community_id" => 0
"facility_id" => 1
"responsible_signer" => null
"responsible_two_signer" => null
"witness_signer" => null
"community_signer" => null
]
#changes: []
#casts: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:1 [▶]
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
#guarded: array:1 [▶]
}
]
}
答案 0 :(得分:0)
此问题已解决
问题出在这里
@if($document->community_signer == $user->current_facility_id && $document->packet->live)
它已更改为
@if($document->community_signer === $user->id && $document->packet->live === 1)