I want to query list of persons based on age. Then, the query will calculate the age using lahir_yy column(birth year value) and search for the list.
$newitem = DB::table('itemregistrations')
->when(request('age'), function($query){
$query->whereRaw('YEAR(CURDATE()) - lahir_yy >= ?', [request('age')]);})
->get();
However, the code doesn't work. It doesn't filter the age but giving no error.
Try with small change. Send
request('age')
in closure. Hope this will work.