Laravel : How to hide user's own profile from friend list?












-1















There are three tables: users, profiles, friend_request



profiles table's column : profile_id, id (foreign key with users) , first_name,last_name



friend_request's table column : request_id, sender_id,to_user_id, request_status



logic : if profile_id exist in either sender_id column or to_user_id of friend_request table with request_status 2 then they are friends.



example : sender_id to_user_id request_status



           5          6            2

$request_accept = DB::table('friend_request')->select('profiles.profile_id','profiles.first_name',
'friend_request.request_id')->leftjoin('profiles', function($join)
{
$join->on('friend_request.sender_id' , '=','profiles.profile_id');
$join->orOn('friend_request.to_user_id' , '=','profiles.profile_id');
}
)->where('to_user_id',$my_profile_id)->orwhere('sender_id',$my_profile_id)->where('interest_status','2')->whereNotIn('profiles.profile_id', function($q) use ($my_profile_id)
{
$q->select('profile_id')->from('profiles')->where('profile_id',$my_profile_id);
})->groupby('profiles.profile_id')->get();


wherenotin i snot working.










share|improve this question





























    -1















    There are three tables: users, profiles, friend_request



    profiles table's column : profile_id, id (foreign key with users) , first_name,last_name



    friend_request's table column : request_id, sender_id,to_user_id, request_status



    logic : if profile_id exist in either sender_id column or to_user_id of friend_request table with request_status 2 then they are friends.



    example : sender_id to_user_id request_status



               5          6            2

    $request_accept = DB::table('friend_request')->select('profiles.profile_id','profiles.first_name',
    'friend_request.request_id')->leftjoin('profiles', function($join)
    {
    $join->on('friend_request.sender_id' , '=','profiles.profile_id');
    $join->orOn('friend_request.to_user_id' , '=','profiles.profile_id');
    }
    )->where('to_user_id',$my_profile_id)->orwhere('sender_id',$my_profile_id)->where('interest_status','2')->whereNotIn('profiles.profile_id', function($q) use ($my_profile_id)
    {
    $q->select('profile_id')->from('profiles')->where('profile_id',$my_profile_id);
    })->groupby('profiles.profile_id')->get();


    wherenotin i snot working.










    share|improve this question



























      -1












      -1








      -1








      There are three tables: users, profiles, friend_request



      profiles table's column : profile_id, id (foreign key with users) , first_name,last_name



      friend_request's table column : request_id, sender_id,to_user_id, request_status



      logic : if profile_id exist in either sender_id column or to_user_id of friend_request table with request_status 2 then they are friends.



      example : sender_id to_user_id request_status



                 5          6            2

      $request_accept = DB::table('friend_request')->select('profiles.profile_id','profiles.first_name',
      'friend_request.request_id')->leftjoin('profiles', function($join)
      {
      $join->on('friend_request.sender_id' , '=','profiles.profile_id');
      $join->orOn('friend_request.to_user_id' , '=','profiles.profile_id');
      }
      )->where('to_user_id',$my_profile_id)->orwhere('sender_id',$my_profile_id)->where('interest_status','2')->whereNotIn('profiles.profile_id', function($q) use ($my_profile_id)
      {
      $q->select('profile_id')->from('profiles')->where('profile_id',$my_profile_id);
      })->groupby('profiles.profile_id')->get();


      wherenotin i snot working.










      share|improve this question
















      There are three tables: users, profiles, friend_request



      profiles table's column : profile_id, id (foreign key with users) , first_name,last_name



      friend_request's table column : request_id, sender_id,to_user_id, request_status



      logic : if profile_id exist in either sender_id column or to_user_id of friend_request table with request_status 2 then they are friends.



      example : sender_id to_user_id request_status



                 5          6            2

      $request_accept = DB::table('friend_request')->select('profiles.profile_id','profiles.first_name',
      'friend_request.request_id')->leftjoin('profiles', function($join)
      {
      $join->on('friend_request.sender_id' , '=','profiles.profile_id');
      $join->orOn('friend_request.to_user_id' , '=','profiles.profile_id');
      }
      )->where('to_user_id',$my_profile_id)->orwhere('sender_id',$my_profile_id)->where('interest_status','2')->whereNotIn('profiles.profile_id', function($q) use ($my_profile_id)
      {
      $q->select('profile_id')->from('profiles')->where('profile_id',$my_profile_id);
      })->groupby('profiles.profile_id')->get();


      wherenotin i snot working.







      laravel query-builder laravel-query-builder






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 13:16







      Entrepreuner

















      asked Nov 15 '18 at 12:39









      EntrepreunerEntrepreuner

      235




      235
























          1 Answer
          1






          active

          oldest

          votes


















          1














          If I understand what you are asking...



          Probably better to make these all models, with relationships, then you could do a much simpler query, for example like this.



          Assume your friend_request table now has a FriendRequest model with a user relationship. The query below uses a $userId, assume this is the ID for the user whom you wish to get all the friend requests.



          FriendRequest::where('to_user_id', $my_profile_id)->get();


          If everything is set up correctly, the user will not be returned as they cannot send themselves a friend request.






          share|improve this answer
























          • i am using query builder not eloquent.

            – Entrepreuner
            Nov 15 '18 at 13:45






          • 1





            Good luck then.

            – John Halsey
            Nov 15 '18 at 13:46











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319703%2flaravel-how-to-hide-users-own-profile-from-friend-list%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          If I understand what you are asking...



          Probably better to make these all models, with relationships, then you could do a much simpler query, for example like this.



          Assume your friend_request table now has a FriendRequest model with a user relationship. The query below uses a $userId, assume this is the ID for the user whom you wish to get all the friend requests.



          FriendRequest::where('to_user_id', $my_profile_id)->get();


          If everything is set up correctly, the user will not be returned as they cannot send themselves a friend request.






          share|improve this answer
























          • i am using query builder not eloquent.

            – Entrepreuner
            Nov 15 '18 at 13:45






          • 1





            Good luck then.

            – John Halsey
            Nov 15 '18 at 13:46
















          1














          If I understand what you are asking...



          Probably better to make these all models, with relationships, then you could do a much simpler query, for example like this.



          Assume your friend_request table now has a FriendRequest model with a user relationship. The query below uses a $userId, assume this is the ID for the user whom you wish to get all the friend requests.



          FriendRequest::where('to_user_id', $my_profile_id)->get();


          If everything is set up correctly, the user will not be returned as they cannot send themselves a friend request.






          share|improve this answer
























          • i am using query builder not eloquent.

            – Entrepreuner
            Nov 15 '18 at 13:45






          • 1





            Good luck then.

            – John Halsey
            Nov 15 '18 at 13:46














          1












          1








          1







          If I understand what you are asking...



          Probably better to make these all models, with relationships, then you could do a much simpler query, for example like this.



          Assume your friend_request table now has a FriendRequest model with a user relationship. The query below uses a $userId, assume this is the ID for the user whom you wish to get all the friend requests.



          FriendRequest::where('to_user_id', $my_profile_id)->get();


          If everything is set up correctly, the user will not be returned as they cannot send themselves a friend request.






          share|improve this answer













          If I understand what you are asking...



          Probably better to make these all models, with relationships, then you could do a much simpler query, for example like this.



          Assume your friend_request table now has a FriendRequest model with a user relationship. The query below uses a $userId, assume this is the ID for the user whom you wish to get all the friend requests.



          FriendRequest::where('to_user_id', $my_profile_id)->get();


          If everything is set up correctly, the user will not be returned as they cannot send themselves a friend request.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 13:43









          John HalseyJohn Halsey

          900725




          900725













          • i am using query builder not eloquent.

            – Entrepreuner
            Nov 15 '18 at 13:45






          • 1





            Good luck then.

            – John Halsey
            Nov 15 '18 at 13:46



















          • i am using query builder not eloquent.

            – Entrepreuner
            Nov 15 '18 at 13:45






          • 1





            Good luck then.

            – John Halsey
            Nov 15 '18 at 13:46

















          i am using query builder not eloquent.

          – Entrepreuner
          Nov 15 '18 at 13:45





          i am using query builder not eloquent.

          – Entrepreuner
          Nov 15 '18 at 13:45




          1




          1





          Good luck then.

          – John Halsey
          Nov 15 '18 at 13:46





          Good luck then.

          – John Halsey
          Nov 15 '18 at 13:46




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319703%2flaravel-how-to-hide-users-own-profile-from-friend-list%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine