繁体   English   中英

我想根据当前日期检索两个给定日期之间的元素

[英]I want to retrieve with an element that is between two given dates according to the current date

我正在尝试查询以检索数据库中给出的两个日期之间的出版物,

我认为我的查询有误,因为我根本没有恢复任何东西,你看到什么不对了吗?

<?php

namespace App\Http\Controllers;

use App\Models\OfficialMessage;


class MessageController extends Controller
{
    public function show()
    {
        $today = date('Y-m-d H:i:s');
        $official_message = OfficialMessage::all()
        ->where($today, '>=', 'publication_start_at', '&&', $today, '<=', 'publication_end_at')
        ->sortBy('publication_start_at');

        return view('front.pages.message', [
            'messages' => $official_message,
        ]);
    }
}

像这样替换你的位置:

->where('NOW() >= publication_start_at AND NOW() <= publication_end_at')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM