Comments (13)
Hello Robin,
It should work this way. I will check it out.
from laravel-friendships.
As I can see this is the default behaviour of a Friendship.
For example:
$sender = createUser();
$recipient = createUser();
$sender->befriend($recipient);
$recipient->acceptFriendRequest($sender);
//Result
$recipient->isFriendWith($sender); //true
$sender->isFriendWith($recipient); //true
Now $sender->getAcceptedFriendships()
returns
Illuminate\Database\Eloquent\Collection {#982
all: [
Hootlex\Friendships\Models\Friendship {#984
id: 66,
sender_id: 11,
sender_type: "App\User",
recipient_id: 12,
recipient_type: "App\User",
status: 1,
created_at: "2016-01-15 01:46:18",
updated_at: "2016-01-15 01:46:20",
},
],
}
And $recipiend->getAcceptedFriendships()
returns the same
Illuminate\Database\Eloquent\Collection {#982
all: [
Hootlex\Friendships\Models\Friendship {#984
id: 66,
sender_id: 11,
sender_type: "App\User",
recipient_id: 12,
recipient_type: "App\User",
status: 1,
created_at: "2016-01-15 01:46:18",
updated_at: "2016-01-15 01:46:20",
},
],
}
from laravel-friendships.
So, how would I be able to display everything and check if the persons are already friends?
Also, I'm trying to use the package in this way:
User::find(Auth::id())->isFriendWith($userdata->UID)
wich should be rendered something like this:
User::find(18)->isFriendWith(4)
.
But that gives me the following error:
Argument 1 passed to User::isFriendWith() must be an instance of Illuminate\Database\Eloquent\Model, integer given
Yes, I included the package in the user model:
use Hootlex\Friendships\Traits\Friendable;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract
{
use Authenticatable, CanResetPassword, HasRoleAndPermission, Friendable;
...
Can this be a issue? Or how should I handle the package (in my view)?
from laravel-friendships.
The isFriendWith
expects a model as a parameter not an integer. In order to check if two users are friends you have to use it this way:
User::find(18)->isFriendWith(User::find(4))
from laravel-friendships.
I will implement a getFriends
method which will return all User friends instead of returning Friendship objects.
from laravel-friendships.
It worked. Could you maybe also implement a function that checks if a user has a pending request of another user?
Something like
User::find(Auth::id())->isPendingFriend(User::find($userdata->UID))
The Auth returns the current user id and the $userdata->UID is the ID of the users profile i'm watching on.
This would be handy for me like if a users has a pending request, of user X, I can display a cancel button to cancel the request.
from laravel-friendships.
Checking friendship status between two users can be easily done via getFriendship()
.
example:
$friendship = $sender->getFriendship($recipient)
if($friendship->status == Status::PENDING){
//your code
}
$friendship
is an instance of Friendship.
Hootlex\Friendships\Models\Friendship {#962
id: 333,
sender_id: 441,
sender_type: "App\User",
recipient_id: 445,
recipient_type: "App\User",
status: 0,
created_at: "2016-01-16 01:36:08",
updated_at: "2016-01-16 01:36:08",
}
from laravel-friendships.
I found something else (made some new code in your package).
But when I try to count how many friends someone has, it returns 1 already on the requested friend.
So Current friends: User A: 0 User B: 0.
When user B request a friendship to user A, User A has 1 friend (not accepted yet) and user B has 0 friends. Code that I'm using:
User::find($userdata->UID)->getAcceptedFriendships()->count()
I don't know how I can use it in any other way?
from laravel-friendships.
Maybe you are using an old version. This is fixed in v1.0.7.
Also I have added $user->getFriends()
in v1.0.8!
from laravel-friendships.
Cool! Now this works like a charm! Thanks for adding my requested features! If you need any help, just give me a shout 😄
from laravel-friendships.
Thanks! :)
from laravel-friendships.
Hi, can this system avoid duplicate rows of relationship. Example - can sender_id, recipient - 3,2 be stored as 2,3, so that makes 2 records for the same relationship.
from laravel-friendships.
Well if one row already exists, then you'll have a "friendship". But if there are two rows like you say (wich you can avoid in your project) will not affect the output.
from laravel-friendships.
Related Issues (20)
- getAcceptedFriends not returning the user details HOT 7
- can't send friend request HOT 2
- how do i use UUID HOT 2
- Call to undefined method App\User::getPendingsCount() HOT 2
- PHP 7.2 count() Issue HOT 2
- Friendship Status HOT 2
- "Incorrect table name" after publishing the vendor HOT 2
- Does not work with Laravel 5.8 (Event::fire) HOT 12
- laravel issue when I add notes to database HOT 3
- laravel-friendships needs a maintainer HOT 10
- How To Fetch Posts For only friends HOT 2
- Will this work HOT 3
- How do you check relationship with other user before sending a friend request? HOT 1
- Support for Laravel 6
- Laravel 7 support HOT 7
- Is this still maintained? HOT 3
- Replace usage of deprecated Illuminate\Events\Dispatcher::fire() HOT 4
- Composer install hootlex requires version ~5.* HOT 13
- Why getFriends method returns all friends ? HOT 4
- Method Illuminate\Events\Dispatcher::fire does not exist HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-friendships.