-1

I've googled for minutes and couldn't find an answer to my question. I want to search users with a string that have certain characters in the name and have a specified id_admin.

I want this

 select * from users where name like '%searching name%' and id_admin = 300;

I am trying this

 $resultado = User::where("name", "like", '%'. $nome . '%')->orWhere(function ($query) {
        $query->where('id_admin', 300);
            })->get();

This is ignoring the 300

notExactlyAHero
  • 353
  • 1
  • 4
  • 14
  • 2
    Possible duplicate of [How to create multiple where clause query using Laravel Eloquent?](https://stackoverflow.com/questions/19325312/how-to-create-multiple-where-clause-query-using-laravel-eloquent) – linktoahref Aug 30 '18 at 12:26

4 Answers4

2

try this

$resultado = User::where([["name", "like", '%'. $nome . '%'],['id_admin', '300']])->get();
0

use:

$resultado = User::where("name", "like", '%'. $nome . '%')->where('id_admin', 300)->get();
Jinal Somaiya
  • 1,931
  • 15
  • 29
0

It should be like this:

$resultado = User::where('id_admin', 300)->where("name", "like", '%'. $nome . '%')->get()
narayansharma91
  • 2,273
  • 1
  • 12
  • 20
0
$resultado = User::where([
  ['column_1', '=', 'value_1'],
  ['column_2', '<>', 'value_2'],
  [COLUMN, OPERATOR, VALUE],
  ...
])
John Humphreys
  • 37,047
  • 37
  • 155
  • 255