【问题标题】:to display data by date in laravel 5在 laravel 5 中按日期显示数据
【发布时间】:2020-02-03 15:19:47
【问题描述】:

按日期显示数据。例如,有多个考试时间表,时间表 1 已超过今天的日期,而下一个日期还有另一个时间表。好吧,我想显示下一个时间表。这是我的代码:

$id_user = g('id_user');
$user = DB::table('user')->where('id', $id_user)->first();
$divisi = $user->id_divisi;
$date =date('d-m-Y');
$schedule = DB::table('schedule')
                ->where('id_divisi', $divisi)
                ->orderBy('date_exam', 'DESC')
                ->get();

$response['api_status'] = 1;
$response['api_message'] = 'Success';
$response['api_authorization'] = 'You are in debug mode !';
$response['data'] = $schedule;
$response['api_http'] = 200;

response()->json($response)->send();

您使用什么或其中是否有示例脚本?帮帮我,谢谢。

【问题讨论】:

    标签: php laravel laravel-5 eloquent query-builder


    【解决方案1】:

    您需要在查询中添加额外的约束以避免过去的时间表。试试这个:

    $schedule = DB::table('schedule')
                ->where('id_divisi', $divisi)
                ->whereDate('date_exam', '>=', date('Y-m-d'))) // <----
                ->orderBy('date_exam', 'DESC')
                ->get();
    

    您可以在the documentation 中获得有关此功能的更多信息,也可以在there is an article 中了解此功能的工作原理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-07
      • 2015-08-10
      • 1970-01-01
      • 2016-03-13
      • 1970-01-01
      • 1970-01-01
      • 2018-04-27
      • 1970-01-01
      相关资源
      最近更新 更多