How can I query raw via Eloquent?

前端 未结 8 1076
眼角桃花
眼角桃花 2020-12-02 20:42

I am trying to do a query in my Laravel app and I want to use a normal structure for my query. This class either does use Eloquent so I need to find something to do a query

相关标签:
8条回答
  • 2020-12-02 21:06

    use DB::statement('your raw query here'). Hope this helps.

    0 讨论(0)
  • 2020-12-02 21:14

    use Eloquent Model related to the query you're working on.

    and do something like this:

    $contactus = ContactUS::select('*')
        ->whereRaw('id IN (SELECT min(id) FROM users GROUP BY email)')
        ->orderByDesc('created_at')
        ->get();
    
    0 讨论(0)
提交回复
热议问题