Sorting UNION queries with Laravel 4.1

前端 未结 5 1309
后悔当初
后悔当初 2020-12-19 09:44

I think there is something changed in the union between Laravel 4 and Laravel 4.1. I have 2 models.

$pho         


        
5条回答
  •  余生分开走
    2020-12-19 10:12

    I don't really know Laravel, but I'll bet this will do it:

    $photos = DB::table('photos')->select('id', 'name', 'created_at');
    $videos = DB::table('videos')->select('id', 'name', 'created_at');
    $combined = $photos->union($videos)->orderBy('created_at', 'desc');
    

提交回复
热议问题