Laravel友谊获取用户信息

编程入门 行业动态 更新时间:2024-10-17 07:23:10
本文介绍了Laravel友谊获取用户信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用hootlex的友谊包,但我不太确定如何当我收到所有好友请求并在foreach循环中显示它们时,获取用户信息(用户名等).

I'm using the friendship package by hootlex but I'm not quite sure how I get the user information (username etc.) when I'm getting all friend requests and displaying them in a foreach loop.

基本上我要做的是返回视图:

Basically what I have done is this, to return the view:

/** * @return mixed * * View friend requests */ public function getFriendRequests() { $user = Auth::user(); return view('friends.requests') -> with([ 'profile' => $user -> profile, 'user' => $user, 'received_requests' => $user -> getFriendRequests(), 'sent_requests' => $user -> getPendingFriendships() ]); }

然后在我看来:

<div class="block block-green"> <div class="block-head"> <h4><i class="fa fa-fw fa-exclamation-circle"></i>Venneforespørsler ({{ count($received_requests) }})</h4> </div> <div class="block-body"> @foreach ($received_requests as $rr) <div class="request"> <div class="thumb">{{-- PROFILE THUMB HERE --}}</div> <div class="username">{{-- SENDERS USERNAME HERE --}}</div> <div class="actions"> <form method="post" action="/friends/request/accept/{{ $rr -> id }}"> <button type="submit" class="btn btn-success"><i class="fa fa-fw fa-check"></i>Aksepter</button> </form> <form method="post" action="/friends/request/deny/{{ $rr -> id }}"> <button type="submit" class="btn btn-danger"><i class="fa fa-fw fa-times"></i>Avslå</button> </form> </div> </div> @endforeach </div> </div>

所以基本上我想知道的是,如何在每个好友请求中从User模型中获取用户名/其他信息?

So basically what I'm wondering, how would I get the username / other information from the User model on each friend request?

谢谢.

推荐答案

您的 $ rr 变量包含类 Hootlex \ Friendships \ Models \ Friendship 的对象-您可以在此处查看其源代码: github /hootlex/laravel-friendships/blob/master/src/Models/Friendship.php .

Your $rr variable contains an object of class Hootlex\Friendships\Models\Friendship - you can see its source code here: github/hootlex/laravel-friendships/blob/master/src/Models/Friendship.php.

如您所见,该模型允许您通过同名属性访问给定朋友请求的发件人和收件人.

As you can see, this model allows you to access both sender and recipient of given friend request via properties of the same name.

因此,为了获取发件人的用户名,您需要使用以下命令进行访问:

Therefore, in order to get username of the sender, you'll need to access it with:

$rr->sender->username

更多推荐

Laravel友谊获取用户信息

本文发布于:2023-11-13 22:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585515.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:友谊   用户信息   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!