-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
  • 13
  • 1
  • 7

2 Answers2

0

Query Builder

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

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

CodeGuru
  • 3,539
  • 12
  • 53
  • 97
0

You can use where like

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

Read documentation here

Abhay Maurya
  • 10,668
  • 6
  • 42
  • 58
Poldo
  • 1,914
  • 1
  • 10
  • 27