I have the following query and i want to know if this is possible in laravel's querybuilder:
SELECT * FROM table WHERE (column = value OR column = value2) AND column2 LIKE '%value3%'
Your query should look like this:
DB::table('table')
->where(function($q) use ($value, $value2) {
$q->where('column', $value)
->orWhere('column', $value2);
})
->where('column2', 'like', '%'.%value3.'%')
->get();
If you have multiple values, you can put them into a simple array and use whereIn()
:
DB::table('table')
->whereIn('column', $valuesArray)
->where('column2', 'like', '%'.%value3.'%')
->get();
you can use closure in where for ex.
\DB::table('table_name')
->where(function($q){
$q->where('column', 'value1')
->orWhere('column', 'value2');
})
->where('column2', 'LIKE', '%value3%');
check here https://laravel.com/docs/5.3/queries#parameter-grouping
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With