mercredi 24 octobre 2018

Join Query in laravel to avoid report abused users

I'm trying to create a join between two tables to avoid report abuse uses in user listing what I'm doing is given below:

What I have I've 2 tables which are

users Table

id |  name  |  
1  |  testA | 
2  |  testB |
3  |  testC |
4  |  testD |
5  |  testE |

report_abuse Table

id | reported_by|  reported_to
1  | 1          |  2
2  | 1          |  3 

now what i need is when I query I should get only 2 records 4 and 5

What I did I create a query to fetch the above records which is :

DB::table('users as U')
->select('U.id','U.name')
->where('U.id', '!=', auth()->user()->id)
->leftJoin('report_abuse as RA', 'RA.reported_by', '=', 'U.id')
->where('RA.reported_by', '=', auth()->user()->id)
->where('RA.reported_to', '!=', 'U.id')
->orderBy('U.id', 'desc')
->paginate(10);

I'm doing something wrong here that's why I'm not getting proper results.

Can you guys please help me out, much appreciated.

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire