I'm a noob in Laravel. can anyone help me write this query in eloquent
SELECT
*
FROM
table
WHERE
(
STR_TO_DATE(`date`, '%m/%d/%Y') BETWEEN '2014-08-05'
AND '2014-08-05'
)
ORDER BY
id
I'm a noob in Laravel. can anyone help me write this query in eloquent
SELECT
*
FROM
table
WHERE
(
STR_TO_DATE(`date`, '%m/%d/%Y') BETWEEN '2014-08-05'
AND '2014-08-05'
)
ORDER BY
id
If you want to use your query as is, just use DB::raw
http://laravel.com/docs/queries#raw-expressions
DB::raw(SELECT * FROM table WHERE ( STR_TO_DATE(date, '%m/%d/%Y') BETWEEN '2014-08-05' AND '2014-08-05' ) ORDER BY id);
Well making the assumption that your model is called Table
, if your field is of type DATE
, you can do this:
Table::where('date', '>=', '2014-08-05')
->where('date', '=<', '2014-08-05')
->get();
Alternatively you can do:
Table::select('table.*', DB::raw("STR_TO_DATE(date, '%m/%d/%Y') as date_format"))
->where('date_format', '>=', '2014-08-05')
->where('date_format', '=<', '2014-08-05')
->get();
You may try this:
$from = '...';
$to = '...';
DB::table('table')->whereBetween('date', array($from, $to))->get();
Or using Eloquent:
ModelName::whereBetween('date', array($from, $to))->get();