jeudi 23 mai 2019

How to make block and unblock user condition laravel

I am stuck at this code, code properly working but in index.blade.php foreach loop not working properly. I am try to show if one user block multiple user then "Unblock" button show in only those user's profile to the one user, else show block button to everyone .

Here Is My UserController

public function blockUser(Request $request, $username){

         $blocked = User::where('id', Auth::user()->id)->first();
            if (blockuser::where("block_username", "=", $username)->first())
          {
              $blocked = blockuser::where('block_username', $username)->first();
                 $blocked->delete();

          }else{

               $blocked = new blockuser;
                 $blocked->user_username = $request->user_username;
                 $blocked->block_username = $request->block_username;
                 $blocked->b_status = '1';
                 $blocked->save();
                }
               $user = User::where('username', $username)->first();
               $userprofile = userprofile::where('user_id', Auth::user()->id)->first();
               $blocked = blockuser::where('user_username', Auth::user()->username)->get();
               return view('profile.index',compact('user', 'userprofile', 'blocked'));


   }

If data is empty block button is showing and one user block to another user 'Unblock' button also show properly but after click to unblock button else condition not working, block button does not show. What can i do please help me.

Here is profile/index.blade.php

    @foreach($blocked as $block)
                   @if(empty($block->user_username ))
                     <a href="#0" class="cd-popup-trigger">Block</a>

                   @else
                        @if(Auth::user()->username == $block->user_username and $user->username == $block->block_username)
                         <a href="#0" class="cd-popup-trigger">Unblock</a>
                         @else
                            <a href="#0" class="cd-popup-trigger">Block</a>
                        @endif
                    @endif
   @endforeach  

Here Is my block_users table

id    user_username   block_username
1      
2
3
4



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire