-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Add access to query builder with requests() and friendships() method in friendable trait #16
base: master
Are you sure you want to change the base?
[WIP] Add access to query builder with requests() and friendships() method in friendable trait #16
Conversation
3df001a
to
855c81f
Compare
I have a question, method |
All of |
This PR seems to do a bit much, but it would be nice to be able to query the friendships and add own scopes/filters/orders. So get the query builder instead of the fetched collection. |
@shinbuntu @barryvdh Yeah, accessing the query builder would make the package much more flexible. The basic idea is that: // returns the query builder
$user->friendships();
// query requests from others users than the current
$user->friendships()->incoming();
// returns all incoming friendships
$user->friendships()->incoming()->get(); |
Hmm, but doesn't the morphMany work one-way? Eg. only the friendships where the current user is the sender, not the other way around? |
Oh friendships are 'requests' and friends are connected friends, right? |
@barryvdh Yup, it's actually too confusing. I think that the idea is that I can't decide how to name the methods/scopes in the new version of the API. Do you have anything to suggest? |
I think friends /friendships or connections when accepted. Requests can be all. $user->requests()->pending(). Or more specific friendRequests() |
Both "friends" method and "requests" method will return a queryBuilder to get a collection of users ? Or "requests" method will return a queryBuilder to get a collection of FriendshipRequest (Actually Friendship model) ? |
Hmm, maybe we can keep only What do you think about that? |
0cb729d
to
46796dc
Compare
I added friendships() to get friends querybuilder, deprecated friends method and added protected friendshipRequests to keep morphMany relationship with Friendship Model. For "$user->requests()->pending()", the requests should be incoming only or incoming+outgoing ? |
I liked your idea with the |
I added some scopes, but I have encountered some difficulties with outgoing and incoming scopes because I can't get User object in the scopes. Maybe a solution consists to add named scopes and remove one scope to filter. (See where clauses in findRequests) Examples:
When I call outgoing(), it will remove scope2 and add scope1. Better solution ? |
I don't know if there is a better way to get the User. I can review it tomorrow and let you know if I find a better solution. |
Thank you. I will check tomorrow night. |
I couldn't find any way to get user withing incoming/outgoing scopes. |
f0ecc0f
to
94fd56f
Compare
@stephane-monnot Let me know when you are done. |
You can already check if you have time. You can quickly see changes in this commit. Maybe we should deprecate some methods, update the documentation and make a deprecated section with all deprecated methods. What do you think about that? Do you have any suggestions ? |
Looks awesome! Though, Do you prefer |
To be honest, I liked the |
Me too. I will try to find a solution. |
@stephane-monnot I can't wait to write proper docs for V2. |
Sorry, I have a lot of work. I will work on it soon. |
@stephane-monnot sure, no problem. Just wanted to let u know 😄 |
salut je n'arrive pas implémenter le package dans mon projet laravel pour la gestion d'amis |
No description provided.