laravel relationships orderby

2016-04-25 21:27:15 902 次浏览

laravel 关系进行orderBy操作
/**
 * Created by PhpStorm.
 * User: lvyahui
 * Date: 2016/4/15
 * Time: 19:09
 */
class ProjectController extends BaseController
{
    protected function buildViewQuery(&$query)
    {
        /*
        $query->load('qsts',function($subQuery){
            $subQuery->orderBy('id');
        });
        */
        $query->with(array('qsts'=>function($subQuery){
            $subQuery->orderBy('id');
        }));
    }
}

评论