samedi 29 avril 2017

Laravel multiple WHERE clauses

I have a requirement to add multiple where clauses to a Laravel SQL query.

So far my PHP code has been:

date_default_timezone_set('America/Los_Angeles');

$today = getdate();
$year = $today['year'];
$month = $today['mon'];
$day = $today['mday'];

$today_ = $day.'-'.$month.'-'.$year;
$result = DB::table('task')
    ->select('*')
    ->where(
        ['rowstate', '<>', 'Ready'],
        ['DATE_FORMAT(due_date, "%d-%m-%y")', '<', $today_])
    ->get();

But above code returns:

Column not found: 1054 Unknown column '0' in 'where clause' 
(SQL: select * from `task_tab` where (`0` = rowstate and `1` = <> and `2` = Ready))

I want to generate below SQl statement:

SELET * 
FROM task
WHERE rowstate <> 'Ready'
AND DATE_FORMAT(due_date, "%d-%m-%y") < $today



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2oSaMZP
via IFTTT

Aucun commentaire:

Enregistrer un commentaire