How do I compare dates using Eloquent in Laravel? -


when run code,

$entry_id = entry::where(function($q)use($intern,$input){                     $q->where('interna_id',$intern['id']);                     $q->where('created_at','=','2015-06-06');                 })->first(['id']); 

it gives

select `id` `entries` (`interna_id` = 1 , `created_at` = 2015-06-06) limit 1 

and can see, date not enclosed in ''. causes problem , mysql not able find record. example, if add '', so,

select `id` `entries` (`interna_id` = 1 , `created_at` = '2015-06-06') limit 1  

the query able retrieve correct record.

note:the created_at using date format, not datetime

created_at of type date laravel. uses carbon package , expects such object. have like:

$entry_id = entry::where(function($q)use($intern,$input){                     $q->where('interna_id',$intern['id']);                     $q->where('created_at','=', carbon::parse('2015-06-06'));                 })->first(['id']); 

please note have include library on page using;

use carbon\carbon;enter code here

alternatively use db::raw date (untested):

$entry_id = entry::where(function($q)use($intern,$input){                     $q->where('interna_id',$intern['id']);                     $q->where('created_at','=', \db::raw('2015-06-06'));                 })->first(['id']); 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -