therubby
therubby

Reputation: 65

Laravel Query DB Get Results from 2 Users with ID

I work on an Message System and i want Query the conversation between 2 Users. I cant use Controller now, soo i must try it on this way.

I want display the Results for example Title between my User ID Auth::user and the Senders ID.

Where "to" is my ID= Auth::user : ->where('to',

How can i change this Code, because with my Code i see all Messages from me and not only between my ID and the Other part ID:

<?php $subjects = DB::table('messages')->where('to', '=', Auth::user()->id)->pluck('title'); echo $subject; ?>

Thanks

Upvotes: 1

Views: 163

Answers (1)

S&#233;rgio Reis
S&#233;rgio Reis

Reputation: 2523

You can add a second where clause, just chain them like this

<?php $subjects = DB::table('messages')->where('to', '=', Auth::user()->id)->where('from', '=', $senders_id)->pluck('title'); echo $subject; ?>

Check documentation for more information about query building https://laravel.com/docs/5.5/queries#where-clauses

Upvotes: 2

Related Questions