0

how can I convert this query in query builder.

public function ajaxsearch(string $value = null) //for search, from sidebar
{
    return $value ? Teacher::select('id', 'efirst', 'esecond')
        ->whereRaw("UPPER(efirst) LIKE '" . strtoupper($value) . "%'")
        ->limit(7)
        ->get() : [];
}

I tried the following but how to convert cases to uppercase in laravel.

DB::table('teachers')
    ->select("id", "efirst", "esecond")
    ->limit(7)->get() : [];
2
  • you're using query builder in both cases. Dont transform to upper in your database query, do it client side. Commented Nov 4, 2019 at 8:24
  • Teacher:: is model, how it is not? Commented Nov 4, 2019 at 8:28

1 Answer 1

1

Try this query :

Teacher::select('id', 'efirst', 'esecond')
->whereRaw("UPPER(efirst) LIKE '" . strtoupper($value) . "%'") 
->limit(7)->get();

for DB Query :

return $value ?
DB::table('teachers')
->select('id', 'efirst', 'esecond')
->whereRaw("UPPER(efirst) LIKE '" . strtoupper($value) . "%'")
->limit(7)
->get():[]; 
Sign up to request clarification or add additional context in comments.

8 Comments

it returned nothing on fronend, here is log; [2019-11-04 09:20:11] local.INFO: array ( 0 => 'select id, UPPER(efirst), esecond from teachers where UPPER(efirst) LIKE \'%A%\' limit 7', 1 => array ( ), 2 => 6.01,
what you exactly want? columns in upper case? or compare records in upper case?
i want to get record from database(any case) and show result in upper case.
in your column efirst it is stored in upper case?
it has come values in lower case and some upper.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.