Please help me to use multiple conditions in Codeigniter 4?
I have used the following codes but it doesn't work, threw an error, with one like its working fine.
$users = $model->like('title', $this->request->getVar('search'))->like('name', $this->request->getVar('search'))->get();
$db = \Config\Database::connect();
$user = $db->table('staff');
$user = $db->like('title', $this->request->getVar('search'));
$user = $db->or_like('name', $this->request->getVar('search'));
$query = $user->get();
Your second code is using or_like
but in Codeigniter 4 you should use orLike
:
https://codeigniter4.github.io/userguide/database/query_builder.html
I don't know what type of error it throws (you should have posted it) and which of the two codes is the correct, but your code shoul look like this:
$db = \Config\Database::connect();
$builder = $db->table('staff');
$users = $builder->like('title', $this->request->getVar('search'))->orLike('name', $this->request->getVar('search'))->get();