I am using laravel backpack 4 and I am facing a quite unusual situation.
I am trying to search for values using the like property, so I wrote this code in the setupListOperation method:
$this->crud->addClause('where', function ($query) use ($cat, $intranet) {
$search = request('search');
$query->where('categoria', "news")
->where('is_intranet', $intranet);
if (isset($search) && isset($search['value'])) {
$searchTerm = $search['value'];
$query->where(function ($q) use ($searchTerm) {
$q->where('titolo', 'LIKE', "%{$searchTerm}%")
->orWhere('id', 'LIKE', "%{$searchTerm}%");
});
// dd($query->toSql(), $query->getBindings());
}
});
The final query printed from the dump is as follows:
"select * from `contents` where `categoria` = ? and `is_intranet` = ? and (`titolo` LIKE '%ottobre%' or `id` LIKE '%ottobre%')"
array:2 [
0 => "news"
1 => "0"
]
Now if I paste the query directly in phpmyadmin I can see 3 results:
select * from `contents` where `categoria` = "news" and `is_intranet` = "0" and (`titolo` LIKE "%ottobre%" or `id` LIKE "%ottobre%") LIMIT 100
In laravel instead I doesn’t get any results.
Can anyone see what’s wrong here?
Thanks.