我试图从表中检索今天的值,在我的表中我有created_at列,这是插入行时自动分配的时间戳。我还有一个send_at列,其中我手动插入datetime,当我查询send_at时它有效,但是当我查询created_at列时,我什么都没回来。
$campaigns = SmsCampaign::whereBetween('created_at', array('2017-03-20 12:00:00','2017-03-20 23:59:00'))->paginate(10);
return view('sms_campaign.smscampaign')->with('campaigns', $campaigns);
模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class SmsCampaign extends Model
{
protected $table = 'sms_campaign';
protected $primaryKey = 'id';
//public $timestamps = false;
protected $fillable = [ 'campaign_name', 'content', 'phone_no_list', 'send_time', 'status', 'merchant_id', 'send_type'];
}
答案 0 :(得分:1)
传递Carbon实例:
SmsCampaign::whereBetween('created_at', [
Carbon::parse('2017-03-20 12:00:00'),
Carbon::parse('2017-03-20 23:59.00')
])->paginate(10);