I have some query scope methods defined in an Eloquent model and am calling them in the controller to allow Laravel to build the query using
return View::make('credit_apps/view')->with('creditApps', CreditApp::ApprovalStatus()
->SalesRep()
->Submitted()
->RefReceived()
->get()
);
The error returned by Illuminate is a MySQL syntax error:
Illuminate \ Database \ QueryException SQLSTATE[42000]: Syntax error
or access violation: 1064 You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near '' at line 1 (SQL: select * from `credit_apps`
where `approval_status` = 'Approved' and `sales_rep` = 'Joe Smith' and
`date_received` between '2014-04-30 00:00:00' AND '2014-05-15
00:00:00' and `date_ref_received` between '2014-04-27 00:00:00' AND
'2014-05-30 00:00:00')
However when I parse the query in MySQL Workbench or from the command line it parses just fine although the criteria returns no records, but I knew it wouldn't. Nevertheless, it's a valid query and works fine in MySQL.
What is causing Laravel to throw the error?
SHOW CREATE TABLE
would be immensely helpful. I assume that the date columns areDATETIME
? – charmeleon