-3

I'm trying to use 'LIKE' in Laravel. But in the output whole data is displayed. Is my method correct? If not then correct me.

        $this->uses('Data');
        $a ='nan';
        $options = ['sort' => ['city' => 1]];
        $results = $this->Part->find([],['city','LIKE',"%$a%"],$options);
        return view('testEnv')->with('results',$results);
    }
Ajay Kakde
  • 53
  • 1
  • 7

2 Answers2

1

Query Builder

$data = DB::table('table_name')->where('col_name','LIKE','%'.$variable.'%')->get();

"%$a%" is a string ....

CodeGuru
  • 3,645
  • 14
  • 55
  • 99
0

You can use where like

$users = DB::table('users')
                ->where('name', 'like', 'T%')
                ->get();

Read documentation here

Abhay Maurya
  • 11,819
  • 8
  • 46
  • 64
Poldo
  • 1,924
  • 1
  • 11
  • 27