I’m working with Laravel 5.8 and I have this method:
public function getCourseDefinition()
{
$course_definition = DB::table('getCourseDefinition');
if (request()->has('cod_title') && request('cod_title'))
$course_definition = $course_definition->whereRaw("cod_title = ?", [request('cod_title')]);
}
So it basically checks if the request contains cod_title
, then searches for that particular request('cod_title')
.
But now I need to add LIKE
for returning similar results based on the entered input.
So I tried this instead:
$course_definition = $course_definition->whereRaw("cod_title = ?", 'LIKE', [request('cod_title')]);
But got this error:
Array to string conversion
So whats going wrong here?
How can I add LIKE
to this search query?
2
Answers
whereRaw
only takes two arguments.Define like this
From the Laravel Docs
You can also use
where
eloquent method like so: