mardi 30 août 2016

Query an array passed from a pivot table inside a foreach loop in Laravel

I am looking to create a following system similar to Twitter, as far have come up with below.

I am looking to query the results of a foreach loop to see the current user is already following the profile the current user is on.

Particularly this part is failing:

if($following->pivot
         ->where('follow_id', $account)
         ->where('user_id', $user)){
         echo 'Already followers';

Resulting in "Already followers" every time when the database says otherwise.

$account = the current pages id
$user = the auth id

He is the full code:

if($user !== $account){ 
            echo "Not user profile";
                foreach ($profiles->follow as $following) {
                    if($following->pivot
                        ->where('follow_id', $account)
                        ->where('user_id', $user)){
                            echo 'Already followers';
                    }
                    else
                    {
                        echo 'follow route link';
                    }}}
        else
        {
            echo 'User Profile';         
        }



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bDEETi
via IFTTT

Aucun commentaire:

Enregistrer un commentaire