A
A
Analka2020-01-16 10:31:50
MySQL
Analka, 2020-01-16 10:31:50

Translate Mysql Syntax to Laravel?

Have a request

SELECT t1.user_id 
FROM likes t1
JOIN likes t2 ON t1.user_id = t2.like_user 
             AND t2.user_id = 1
             AND t1.like_user = 1

how do i write it in laravel?
I try like this
$users = DB::table(DB::raw('likes t1'))
       ->join(DB::raw('likes t2'), 't1.user_id', '=', 't2.like_user ')
       ->where('t2.user_id', '=', '1')
            ->where(' t1.like_user', '=', '1')->paginate(15);

but gives out
Base table or view not found: 1146 Table 'extremje_dating.DB::raw('likes t1')' doesn't exist (SQL: select count(*) as aggregate from `DB::raw('likes t1')` inner join `DB::raw('likes t2')` on `t1`.`user_id` = `t2`.`like_user ` where `t2`.`user_id` = 1 and ` t1`.`like_user` = 1)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Adamos, 2020-01-16
@Analka

$users = DB::table('likes AS t1')
       ->join('likes AS t2', 't1.user_id', '=', 't2.like_user ')
       ->where('t2.user_id', '=', '1')
            ->where(' t1.like_user', '=', '1')->paginate(15)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question