mardi 27 octobre 2015

Laravel Eloquent using where pattern

in Laravel 5.1, using WHERE in eloquent usually goes like this :

Model::where('column_name', 'LIKE', '%value%')->firstOrFail();

I'm trying to get a row entry from a PostgreSQL database where a string contains a part of the column -- something like this :

Model::where('value', 'LIKE', '% || column_name || %')->firstOrFail();

I have the value in a variable, and I used it like this :

Model::where($prefix, 'LIKE', "'%' || column_name || '%'")->firstOrFail();

The function returns an error, in which PostgreSQL accepts the value variable as a column name (putting it between double quotes).

column "value" does not exist
LINE 1: ..." where "table"."deleted_at" is null and "manage/us...
^ (SQL: select * from "table" where "table"."deleted_at" 
is null and "value" LIKE '%' || column_name || '%' limit 1)

Is there any fix for this? Or is there any better way to do it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire