Skip to content
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

How To Fetch Posts For only friends #130

Open
ghost opened this issue Aug 29, 2019 · 2 comments
Open

How To Fetch Posts For only friends #130

ghost opened this issue Aug 29, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented Aug 29, 2019

No description provided.

@TechTailor
Copy link

I will have to look into for fetching, but for displaying, maybe you can do something with this -

$user->isFriendWith($friend);

and display only if its true. Not ideal but try it out.

Tell me if it works out.

-TT

@kg-bot
Copy link

kg-bot commented Feb 6, 2020

I have posts that have visibility, and users should see all public posts, all posts made by their friends, and all post created by himself, and I only show posts that will not expire in less then hour (time filter) I did it like this

return $query->where([
            ['visibility_id', $public_visibility_id],
            ['time', '>', $time],
        ])->orWhere(function ($query) use ($only_friends_visibility_id, $user_id, $time) {
            /* @param $query Builder */
            $query->where([
                /** Only friends visiblity */
                ['visibility_id', $only_friends_visibility_id],
                ['time', '>', $time],
            ])->whereIn('created_by', function ($q) use ($user_id, $time) {
                /** My friends where I was sender of request */
                $q->selectRaw(' sender_id FROM friendships WHERE status = ' . Status::ACCEPTED . " AND (`sender_id` = '{$user_id}' OR  `recipient_id` = '{$user_id}') AND time > '{$time}'");
            })
                ->orWhereIn('created_by', function ($q) use ($user_id, $time) {
                    /** My friends where I was recipient of request */
                    $q->selectRaw(' recipient_id FROM friendships WHERE status = ' . Status::ACCEPTED . " AND (`sender_id` = '{$user_id}' OR  `recipient_id` = '{$user_id}') AND time > '{$time}'");
                })
                ->orWhere([
                    ['created_by', $user_id],
                    ['time', '>', $time]
                ])
                ->where('time', '>', $time);
        });

meetups = posts in this example

You can also chain query builder methods to this, paginate, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants