I have a task that needs to be displayed every type of holiday where id is odd number.And when I tried to do it in Eloquent it always gives me an error.
Query
Select holiday_type.id, holiday_type.name
From holiday_type
Where (holiday_type.id % 2) = 0;
Laravel PHP
return DB::table('holiday_type')
->select('holiday_type.id','holiday_type.name as text')
// ->where(('id%2'), '=', 0)) ** I also tried different format but still nothing
->get();
}
You can use raw expression
DB::table('holiday_type')
->select(DB::raw('holiday_type.id, holiday_type.name as text'))
->whereRaw('MOD(id, 2) = 0')
->get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With