V
V
vladimirr892018-03-14 22:45:12
Laravel
vladimirr89, 2018-03-14 22:45:12

How can I separate myself from other users in the controller?

Please tell me how to separate myself and other users of the site (which will be enclosed in the $friend variable). In the task condition, there is me $user and there are others $friend.
I found only $user = Auth::user(); to refer to myself in Laravel. but this applies to everyone. Is there a more precise command?
I need this to run this code:

$users = User::all();
        $user = Auth::user();
        $friend = ??? (хз что тут писать)

$last_message = Chat::select(['chat'])->where('user_id', $user->id)->where('friend_id', $friend->id)->orderBy('id', 'desc')->first();

The chats table consists of the columns: user_id, friend_id, chat
My own attempts to do this did not lead to anything.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question