Laravel. How do I fix Argument 1 passed to Illuminate\Database\Query\Builder::setBindings() must be of the type array, string given

I am trying to get the SUM of records within 7 days. but i got the above error

$today = date('Y-m-d H:i:s');
$week = jobs::Whereraw('DATEDIFF(?,completed_at) <= 7')
             ->setBindings('[$today]')
             ->get();

2 answers

  • answered 2020-06-27 03:51 Kurt Friars

    You made it a string?

        ->setBindings('[$today]')
    

    Should be

        ->setBindings([$today])
    

    No?

  • answered 2020-06-27 03:55 Coder

    Your code will be come like below

    $week = jobs::Whereraw('DATEDIFF(?,completed_at) <= 7')
                 ->setBindings([$today])
                 ->get();
    

    Not string it will [$today]