How do I write the following SQL query in Laravel using Eloquent? How do I write the following SQL query in Laravel using Eloquent? laravel laravel

How do I write the following SQL query in Laravel using Eloquent?


You should try this :

POST::whereIn('post_id', function($query) use($user_id){            $query->select('post_id')                ->from(with(new WATHCHISTORY)->getTable())                ->where('user_id',$user_id);            })->get();

Hope this work for you !!!!


Try this one,

If your user's id is in variable $user_id, you can do it like,

DB::table('post')->whereIn('post_id',    DB::table('watchhistory')->where('user_id',$user_id)->pluck('post_id'))->get();