我有以下代码可显示用户在会议中的下一个注册:
$nextRegistrations = $user->registrations()
->with('participants.registration_type')
->whereHas(
'conference',
function ($query) {
$query->where('end_date', '>', now());
}
)->paginate($pageLimit);
然后,如果“ registration_types”表的“ available_certificate”列的值为“ Y”,则在视图中我希望为每个注册显示一个链接“获取证书”。但是它不适用于“ @if($ nextRegistration-> participants-> contains('certificate_available','Y'))”。你知道为什么吗?对于三个列表项(3个注册),“ {{dump($nextRegistration->participants->contains('certificate_available', 'Y'))}}
”显示为“ false
”。
<ul class="list-group">
@foreach($nextRegistrations as $nextRegistration)
@foreach($nextRegistration->participants as $participant)
@if(!empty($nextRegistration->conference) || !empty($nextRegistration->conference->start_date))
@if ($nextRegistration->participants->contains('certificate_available', 'Y'))
<a href="{{route('conferences.certificateInfo',
[
'regID'=> $nextRegistration->id])}}"
class="btn btn-primary ml-2">Download certificate</a>
@endif
</li>
@endif
@endforeach
@endforeach
</ul>
Db结构:
会议表:
id name
1 conference test 1
注册表:
id conference_id user_that_did_registration
1 1 2
2 1 2
3 1 2
参与者表:
id registration_id registration_type_id name
1 1 1 Jake
2 2 1 John
3 3 1 Paul
4 3 2 Peter
registration_types表:
id name conference_id certificate_id certificate_available
1 r1 1 1 Y
2 r2 1 2 Y
证书表:
id content
1 <p>cert 1</p>
2 <p>cert 2</p>
答案 0 :(得分:0)
我认为您需要过滤然后检查计数,请参阅上面的评论:
@import '~/templates/common/variables'