B
B
BonBon Slick2017-08-12 11:06:51
PostgreSQL
BonBon Slick, 2017-08-12 11:06:51

Laravel Postgres CAST on integer?

$query = Posts::where('owner.name', 'LIKE',  '%' . $text . '%')
                     ->orWhereRaw('CAST(owner.id TEXT) ILIKE "%' . $text . '%"')
                    ->orderBy('owner.id', $order)
                    ->select('posts.*', 'owner.*', )
                    ->leftJoin('users as owner', 'posts.user_id', '=', 'owner.id')
                    ->get();


Gives an error message:
Undefined column: 7 ERROR: column "%2%" does not exist LINE 1: ..._id" =


It seems that such a construction worked before, we use CAST on the field, make it as text and search for the entered text, however, it shows that there is no such table , why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2017-08-12
@BonBonSlick

Because of the double quotes, %2% is treated as a column name. Replace with singles.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question