lundi 9 novembre 2015

Laravel 5.1 Invalid datetime format: 7 ERROR: invalid input syntax for type date error

I've been having trouble with eloquent that keeps returning error. Below is the query that i tried to run in laravel.

$actives = ProjectVersion::join('version_employees as ve', 've.report_id' ,'=', 'project_versions.id')
        ->join('employees as e', 've.employee_id', '=', 'e.id')
        ->whereBetween(\DB::raw("'1985-05-27'::date"),[
            \DB::raw("to_date(timeline->>'start_time', 'YYYY-MM-DD')"),
            \DB::raw("to_date(timeline->>'release_time', 'YYYY-MM-DD')")])
        ->groupBy('e.name')
        ->select(\DB::raw('count(e.id), e.name'))
        ->get();

Now this returns an error of

Invalid datetime format: 7 ERROR: invalid input syntax for type date: "to_date(timeline->>'start_time', 'YYYY-MM-DD')" 

The full query returned by the error message is

SELECT count(e.id), e.name 
FROM "project_versions" inner join "version_employees" as "ve" on "ve"."report_id" = "project_versions"."id" inner join "employees" as "e" on "ve"."employee_id" = "e"."id" 
WHERE '1985-05-27'::date 
     BETWEEN to_date(timeline->>'start_time', 'YYYY-MM-DD')      
     AND to_date(timeline->>'release_time', 'YYYY-MM-DD') 
GROUP BY "e"."name"

The thing is that when i run this query in pgadmin, it runs fine and returns the result that i wants.

I've been stuck for hours debugging this. Any idea on where the problem is ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire