2016-02-13 109 views
1

我在Maxoffer型号:Laravel问题 - 日期格式

protected $dates = [ 
     'start' 
    ]; 

    public function setStartAttribute($date){ 
     $this->attributes['start']= Carbon::createFromFormat('m/d/Y h:i a', $date); 
    } 
    public function getStartAttribute($date){ 
     return (new Carbon($date))->toRfc2822String(); 
    } 

在我的数据库start存储格式:2016年2月2日00:00:00 enter image description here

现在,当我尝试运行WHERE查询:

$maxoffer = Maxoffer::where('article_id', $request->input('article_id')) 
        ->where('start', $request->input('start')) 
        ->first(); 
dd($maxoffer); 

Input(start)是格式为:2016年2月2日上午12:00我也尽量使其格式为:2016年2月2日00:00:00,但agai ñ不工作,所以dd给我结果null 我有一个问题,因为我不知道如何比较开始和输入(开始)。如何让他们在相同的格式...

而且我不能改变:

public function getStartAttribute($date){ 
      return (new Carbon($date))->toRfc2822String(); 
     } 

becouse我需要它,在这种格式为其他的事情。

那么如何使这成为可能?

回答

1

尝试下面,其中串被转换成碳的时间和锋然后可以在DB

->where('start', Carbon::parse($request->input('start'))) 
时间比较