mercredi 3 octobre 2018

Is there a way to use the same parameter into multiple place in the same query with Eloquent?

I am working on a Laravel 5.7 based project in which Eloquent is used as an ORM.

I need to execute a raw SQL statement on my database. However, my query uses the same parameter into multiple places.

Here is a query example "this is not my real query it is more for explaining the question. My actual query is very complex and reuses the same parameters multiple times"

SELECT * FROM table
WHERE a BETWEEN :from AND :to
AND c > :from
AND d < :to

I am expecting the following to work

$resorces = DB::select('SELECT * FROM table
    WHERE a BETWEEN :from AND :to
    AND c > :from
    AND d < :to', ['from' => '2017-01-01 00:00:00', 'to' => '2018-10-01 00:00:00']);

But that is giving me the following error

SQLSTATE[HY093]: Invalid parameter number

How can I re-use the same parameters multiple places in the same query using Eloquent?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire