show user only those products which he hasn 27t buyed laravel eloquent

Solutions on MaxInterview for show user only those products which he hasn 27t buyed laravel eloquent by the best coders in the world

showing results for - "show user only those products which he hasn 27t buyed laravel eloquent"
Montserrat
20 Jun 2020
1$user_id = auth()->user()->id;
2
3Product::where('status', 'active')
4  ->whereNotIn('id', function($query) use ($user_id) {
5    $query->select('product_id')->from((new OrderProduct)->getTable())
6      ->where('user_id', $user_id)->where('status', 'delivered')
7		->pluck('product_id')->toArray();
8  });