Laravel  优雅的 ORM 
                            
                                                    
                        
                    
                    
  
                    
                    laravel 子查询方式1:
return Destination::addSelect(['last_flight' => Flight::select('name')
            ->whereColumn('destination_id', 'destinations.id')
            ->orderBy('arrived_at', 'desc')
            ->limit(1)
])->get();
laravel 子查询方式2:
return Destination::addSelect(['last_flight' => function ($query) { 
            $query->select('name')
            ->from('flights')
            ->whereColumn('destination_id', 'destinations.id')
            ->orderBy('arrived_at', 'desc') 
            ->limit(1);
}])->get();
                        
                        
                                            
          
                    
                    
          
          
                关于 LearnKu
              
                    
                    
                    
 
推荐文章: