Where NOT in pivot table

前端 未结 7 1736
栀梦
栀梦 2020-12-13 19:02

In Laravel we can setup relationships like so:

class User {
    public function items()
    {
        return $this->belongsToMany(\'Item\');
    }
}


        
相关标签:
7条回答
  • 2020-12-13 19:32

    Maybe you can use:

    DB::table('users')
            ->whereExists(function($query)
            {
                $query->select(DB::raw(1))
                      ->from('orders')
                      ->whereRaw('orders.user_id = users.id');
            })
            ->get();
    

    Source: http://laravel.com/docs/4.2/queries#advanced-wheres

    0 讨论(0)
提交回复
热议问题