我无法显示向其他用户发送邮件的用户。请参阅下文以了解我的意思:
我的表格讯息:
Schema::create('messages', function (Blueprint $table) {
$table->id();
$table->integer('de_user_id')->unsigned();
$table->foreign('de_user_id')->references('id')->on('users');
$table->integer('para_user_id')->unsigned();
$table->foreign('para_user_id')->references('id')->on('users');
$table->text('message');
$table->timestamps();
});
我有一个页面,它将显示向其他成员发送消息的用户:
<section class="conversations">
<a href="https://www.example.com/profile/messages/username" class="conversation ">
<div class="info">
<div class="name ">
Marcos
</div>
</div>
<div class="date"><span aria-hidden="true" class="fas fa-circle"></span> 3 months ago
</div>
</a>
</section>
但是要显示发送消息的人,我需要访问表中id
接收消息的人Message
。另外,我需要获取发送它的用户。我的问题是我不知道该如何识别一次发送给谁。这样我就可以收集所有消息。
这是我的做法:
public function msgs(Request $request) {
$msg = Message::where('para_user_id', $request->user()->id)->get();
return view('msgs',compact('msg'));
}
但是我怎么能收到来自同一用户的许多消息。此解决方案不起作用。无论发送了多少消息,我都需要抓住一次发送消息给我的时间。因此,仅返回发送给我消息的用户。
你能帮助我吗 ?
以下应该工作
$msg = Message::where('para_user_id', $request->user()->id)->get()->unique('de_user_id')->values();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句