[英]“Property [registration_types] does not exist on this collection instance.”
I have this code to show the next registrations of a user in a conference: 我有以下代码来显示用户在会议中的下一个注册:
$nextRegistrations = $user->registrations()
->with('participants.registration_type')
->whereHas(
'conference',
function ($query) {
$query->where('end_date', '>', now());
}
)->paginate($pageLimit);
In the view I want to show a link "Get certificate" if the column "available_certificate" of the "registration_types" table has the value "Y". 在视图中,如果“ registration_types”表的“ available_certificate”列的值为“ Y”,我想显示链接“获取证书”。
But with the code below is not working, it appears "Property [registration_types] does not exist on this collection instance." 但是,由于下面的代码不起作用,因此显示“此集合实例上不存在属性[registration_types]”。
@foreach($nextRegistrations as $nextRegistration)
@if ($nextRegistration->participants->registration_types->certificate_available == 'Y')
<a href="{{route('conferences.registrationInfo',['regID'=> $nextRegistration->id])}}"class="btn btn-primary">Get Certificate</a>
@endif
@endforeach
For example if there is only 1 next registration $nextRegistrations shows: 例如,如果下一个注册只有1个,则$ nextRegistrations显示:
LengthAwarePaginator {#325 ▼
...
#items: Collection {#319 ▼
#items: array:1 [▼
0 => Registration {#320 ▼
...
#relations: array:1 [▼
"participants" => Collection {#307 ▼
#items: array:1 [▼
0 => Participant {#321 ▼
...
#relations: array:1 [▼
"registration_type" => RegistrationType {#326 ▶}
]
...
}
]
}
]
...
}
]
}
...
}
Code in the view: 视图中的代码:
<ul class="list-group events-list">
@foreach($nextRegistrations as $nextRegistration)
@if(!empty($nextRegistration->conference) || !empty($nextRegistration->conference->date))
<li class="list-group-item">
<p>{{optional($nextRegistration->conference)->date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
<h5>{{optional($nextRegistration->conference)->name}}</h5>
<p> Registration {{$nextRegistration->created_at }}
</p>
@if ($nextRegistration->invoice == 'Y')
<!-- show some content -->
@endif
@if ($nextRegistration->totalPrice <= 0)
<!-- show some content -->
@endif
@if ($nextRegistration->status == 'C')
<!-- show some content -->
@endif
@if ($nextRegistration->status === 'I')
<!-- show some content -->
@endif
</li>
@endif
@endforeach
</ul>
Change 更改
@foreach($nextRegistrations as $nextRegistration)
@foreach($nextRegistration->participants as $participant)
@if ($participant->registration_type->certificate_available == 'Y')
<a href="{{route('conferences.registrationInfo',['regID'=> $nextRegistration->id])}}"class="btn btn-primary">Get Certificate</a>
@endif
@endforeach
@endforeach
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.