Laravel DB 里的 union 怎么用呢?
我想把同时查询两个表,然后把结果排序:
$topics = Topic::select(['id','title as title2','created_at'])->where('title','like','%'. $keyword .'%')->orwhere('body','like','%'. $keyword .'%');
$test_psies = TestPsy::select(['id','title as title2','created_at'])->where('title','like','%'. $keyword .'%')->orwhere('body','like','%'. $keyword .'%')->union($topics)->latest()->paginate(10);
我要怎么判断哪个来自哪张表?
推荐文章: