I
I
Ismail942020-12-05 08:47:54
Laravel
Ismail94, 2020-12-05 08:47:54

How to make and get data through laravel connection?

I have 2 tables,
1 - users
2 - messages
The messages table has fields - id, sender_id, receiver_id - sender and receiver.
How to make a connection that would receive both sent and received messages in one array.
Separately, it will.

public function incomeMessages()
    {
        return $this->hasMany(UserMessage::class, 'receiver_id');
    }

    public function sentMessages()
    {
        return $this->hasMany(UserMessage::class, 'sender_id');
    }

And how it is possible to receive through communication both sent and received in 1 array?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2020-12-05
@vos_50

->with (['incomeMessages','sentMessages'])->...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question