Mȍhǟmmǟd Șamȋm
Mȍhǟmmǟd Șamȋm

Reputation: 271

Search Query in laravel 5.6

I am using laravel 5.6,

How can I convert below query in laravel query builder or Eloquent?

SELECT * FROM books 
WHERE book_title LIKE '%something%' 
OR book_author LIKE '%something%'
OR *book_description LIKE '%something%' 

I searched a lot in google but I was not able to find any solution to much my problem.

Upvotes: 0

Views: 3348

Answers (2)

arun
arun

Reputation: 4815

Eloquent Version:

Books::where('book_title ','LIKE','%'.$something.'%')
       ->orWhere('book_author ','LIKE','%'.$something.'%')
       ->orWhere('book_description ','LIKE','%'.$something.'%')->get();

Upvotes: 5

Martin
Martin

Reputation: 1279

Using query builder it would look like this:

DB::table('books')
        ->where('book_title', 'like', '%'.$variable.'%')
        ->orWhere('book_author', 'like', '%'.$variable.'%')
        ->orWhere('book_description', 'like', '%'.$variable.'%')
        ->get();

By the way next time just look into the docs: Laravel Docs - Query builder

Upvotes: 4

Related Questions