Php 为什么参与者的名字没有出现?
我在getRegistrationInfo()中有一个查询,用于获取会议中注册的详细信息,因此可以显示与注册相关的每个参与者的列表项 例如,如果用户John在会议“test conference”(测试会议)中注册了他和他的同事Jake,则在注册类型“general”(一般)中,我想显示两个列表项,如:Php 为什么参与者的名字没有出现?,php,laravel,Php,Laravel,我在getRegistrationInfo()中有一个查询,用于获取会议中注册的详细信息,因此可以显示与注册相关的每个参与者的列表项 例如,如果用户John在会议“test conference”(测试会议)中注册了他和他的同事Jake,则在注册类型“general”(一般)中,我想显示两个列表项,如: Conference Name: test conference Registration Type: general Participant: Jake Conference Name: t
Conference Name: test conference
Registration Type: general
Participant: Jake
Conference Name: test conference
Registration Type: general
Participant: John
它对会议名称和注册类型名称有效,但对参与者名称无效,它显示为“{{{$registrationType->participants->participant->name}
”的“正在尝试获取非对象的属性”
你知道问题在哪里吗
getRegistrationInfo()方法:
然后在视图中:
@foreach($registration->conference->registrationTypes as $registrationType)
<li>
<div class="wrapper">
<div class="conference-title">
<strong>Conference</strong><br> <span>{{$registration->conference->name}}</span>
</div>
<div class="conference-regtype">
<div>
<strong>Registration Type </strong><br>
<span>{{$registrationType->name}}</span>
</div>
</div>
<div class="conference-participant">
<strong>Participant</strong><br>
<span>{{$registrationType->participants->participant->name}}</span>
</div>
</div>
</li>
@endforeach
$registrationType的输出:
RegistrationType {#324 ▼
#relations: array:1 [▼
"participants" => Collection {#325 ▼
#items: array:2 [▼
0 => Participant {#331 ▼
#fillable: array:4 [▼
0 => "name"
1 => "surname"
2 => "registration_id"
3 => "registration_type_id"
]
}
1 => Participant {#333 ▼
#fillable: array:4 [▼
0 => "name"
1 => "surname"
2 => "registration_id"
3 => "registration_type_id"
]
}
]
}
]
}
您的输出应如下所示:
@foreach($registration->conference->registrationTypes as $registrationType)
@foreach($registrationType->participants as $participant)
<li>
<div class="wrapper">
<div class="conference-title">
<strong>Conference</strong><br> <span>{{ $registrationType->conference->name }}</span>
</div>
<div class="conference-regtype">
<div>
<strong>Registration Type </strong><br>
<span>{{ $registrationType->name }}</span>
</div>
</div>
<div class="conference-participant">
<strong>Participant</strong><br>
<span>{{$participant->name}}</span>
</div>
</div>
</li>
@endforeach
@endforeach
@foreach($registration->conference->registrationType作为$registrationType)
@foreach($registrationType->参与者作为$participant)
会议
{{$registrationType->Conference->name}
注册类型
{{$registrationType->name}
参与者
{{$participant->name}
@endforeach
@endforeach
您可能需要创建或调整与操作中涉及的模型的关系。我的意思是,请查看错误消息。在该行的某个点上,您试图从非对象中获取属性。您甚至从未显示我可以看到的
$registrationType
的定义,因此我看不出您希望我们如何提供帮助。谢谢,我用$registration的输出更新了问题。您希望->参与者->参与者->名称-/code>做什么?具体来说,->参与者
部分?您是否打算进行数组访问,因为->participants
是一个数组?这里似乎也没有名字。请创建一个。参与者有name字段,我用参与者字段更新问题。参与者仍然没有name
字段,他们是一个数组,其中包含一个值为“name”
的元素。请花点时间创建一个。谢谢,但是第一个参与者的名字是apepars,但是只显示了一个列表项,第一个参与者,但是它应该显示两个列表项,因为有两个参与者。你知道问题出在哪里吗?$registrationType
的输出显示了集合中的两个参与者
项目,你必须迭代它。谢谢我有类似“@foreach($registration->conference->registrationTypes as$registrationType)”的foreach因为还需要获取有关conferene名称和注册类型名称的信息。但我只想在每个列表项中显示参与者的姓名。每个列表项应显示有关参与者姓名、会议名称和注册类型名称的信息,而不是在同一列表项中显示会议名称、注册类型名称和所有参与者姓名。$participant
符合您的要求,$participant->registrationType->name
和$participant->registrationType->conference->name
。谢谢,但在“@foreach($registrationType->参与者为$participant)”中显示“未定义变量:registrationType”。使用“公共函数getRegistrationInfo($regID){$registration=registration::With('conference.registrationTypes.participants')->find($regID);$pdf=pdf::loadView('pdf.registration',compact('registration');return$pdf->download('info.pdf');}”。
RegistrationType {#324 ▼
#relations: array:1 [▼
"participants" => Collection {#325 ▼
#items: array:2 [▼
0 => Participant {#331 ▼
#fillable: array:4 [▼
0 => "name"
1 => "surname"
2 => "registration_id"
3 => "registration_type_id"
]
}
1 => Participant {#333 ▼
#fillable: array:4 [▼
0 => "name"
1 => "surname"
2 => "registration_id"
3 => "registration_type_id"
]
}
]
}
]
}
@foreach($registration->conference->registrationTypes as $registrationType)
@foreach($registrationType->participants as $participant)
<li>
<div class="wrapper">
<div class="conference-title">
<strong>Conference</strong><br> <span>{{ $registrationType->conference->name }}</span>
</div>
<div class="conference-regtype">
<div>
<strong>Registration Type </strong><br>
<span>{{ $registrationType->name }}</span>
</div>
</div>
<div class="conference-participant">
<strong>Participant</strong><br>
<span>{{$participant->name}}</span>
</div>
</div>
</li>
@endforeach
@endforeach