mardi 20 mars 2018

Laravel 5: SELECT REPLACE() does not work

I want to perform a replace within a database query using REPLACE(). In phpMyAdmin, it's no problem using it in a raw query, but Laravel fires an error:

Query:

$p = Products::select('*, REPLACE(abstract, \'[[name]]\', name) AS abstract')
->Paginate(10);

Error:

QLSTATE[42S22]: Column not found: 1054 Unknown column '*,
REPLACE(abstract, '[[name]]', name)' in 'field list' (SQL: select `*,
REPLACE(abstract, '[[name]]', name)` as `abstract` from
`products` limit 3 offset 0)

Eve if I try it with an array like this one, the error occures.

Products::select([ 'name', 'REPLACE(abstract, \'[[name]]\', name) AS abstract' ])
->Paginate(10)

Why isn't it possible to user REPLACE() here?



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

Aucun commentaire:

Enregistrer un commentaire