我正在编写此代码以按顺序获取数据但不能正常工作
$newspaper_more_info = newspaper_jobad::with('sector', 'newspaper', 'province', 'test', 'catagory')->where('test_id', $job_test->id)->orderBy('id', 'DESC')->get();
这个代码用于创建分页并以desc顺序获取数据,但它会引发致命错误
$newspaper_more_info = newspaper_jobad::with('sector', 'newspaper', 'province', 'test', 'catagory')->where('test_id', $job_test->id)->orderBy('id', 'DESC')->paginate(15)->get();
答案 0 :(得分:0)
在执行排序时,可能会混淆从哪个表中获取id。你能否按顺序
提及表名喜欢$newspaper_more_info = newspaper_jobad::with('sector', 'newspaper', 'province', 'test', 'catagory')->where('test_id', $job_test->id)->orderBy('newspaper_jobad.id', 'DESC')->get()
因为它急于加载表格
如果laravel 5.4尝试
->orderByDesc('id')->get()