samedi 21 novembre 2015

If i have Friend i can add him again Laravel 5.1

i have a little problem, i created migration, model etc about Friend, when i add Friend, everything is ok, but do not know how to do that if the user to a particular user in your friends , then I can not add it again. then simply do not see the button.

This is my button:

@if($user->off_friends != 1)
    @if(!\Auth::guest() && $user->id != \Auth::id())
        @if($user->hasFriend($user->id))
            {!! Form::open(array('method'=>'post', 'route' => array('store.friend', $user->id))) !!}
                {!! Form::hidden('friend_id', $user->id) !!}
                {!! Form::hidden('friend_name', $user->name) !!}
                {!! Form::hidden('friend_avatar', $user->avatar) !!}
                {!! Form::submit('Dodaj znajomego', ['class' => 'btn btn-primary btn-xs']) !!}
            {!! Form::close() !!}<BR />
        @endif
    @endif
@endif  

And this is my function:

public function hasFriend($id)
    {
        foreach($this->friend as $friend)
        {
            if(\Auth::id() == $friend->user_id && $friend->friend_id == $id)
            {
                return true;
            }
        }

    }

I waiting for the answer, this is important, thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire