我有一个任务需要显示 id 为奇数的每种类型的假期。当我尝试在 Eloquent 中执行此操作时,它总是给我一个错误。
询问
Select holiday_type.id, holiday_type.name
From holiday_type
Where (holiday_type.id % 2) = 0;
Run Code Online (Sandbox Code Playgroud)
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();
}
Run Code Online (Sandbox Code Playgroud)
您可以使用原始表达式
DB::table('holiday_type')
->select(DB::raw('holiday_type.id, holiday_type.name as text'))
->whereRaw('MOD(id, 2) = 0')
->get();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2086 次 |
| 最近记录: |