如何使用提供程序按 Laravel 5.6 中的降序获取数据

How to Fetch data in Descending order in Laravel 5.6 using provider

我正在使用 App\Provider 主页和管理面板中的广告展示数据从数据库中获取数据。我想按降序对数据进行排序。 app\provider

中的代码
View::composer('*',function($view){
        $view->with('services', Service::all());
    });

如果您想按 Laravel 5.6 中的降序和升序对数据进行排序,只需使用如下简单的代码:

View::composer('*',function($view){
        $view->with('services', Service::latest()->get());
    });

最新函数等于orderBy('created_at', 'DESC');并获取函数帮助从数据库中获取所有数据。 此代码还使用 ('services', Service::latest()->get()) 在控制器中按降序获取数据。 谢谢你 如果您有任何问题,可以随时问我。