我正在使用首页\管理面板中的App \ Provider广告展示数据从数据库中获取数据。我想按降序对数据进行排序。 app \ provider中的代码
View::composer('*',function($view){
$view->with('services', Service::all());
});
答案 0 :(得分:1)
如果要在Laravel 5.6中按降序和降序对数据进行排序,则只需编写简单的代码,如下所示:
View::composer('*',function($view){
$view->with('services', Service::latest()->get());
});
最新函数等于orderBy('created_at', 'DESC');
,并获得函数帮助以从数据库中获取所有数据。
此代码还使用('services', Service::latest()->get())
在控制器中按降序获取数据。
谢谢
如果您有任何疑问,可以问我。