【发布时间】:2021-09-01 09:59:09
【问题描述】:
我是 laravel 的新手。实际上我想过滤一些关于 state 和 typeofsupply 列的数据。就像如果 state="south australia" 和 typeofsupply="Inverter & Storage" 然后向我显示这两个值上都存在的这些行。如果我像 state="south australia" 和 typeofsupply=Nul 进行过滤。那么这些行将显示谁南澳大利亚的存在状态和 typeofsupply 应该是列表中的任何一个(所有类型的供应)
public function show(Request $request){
$typeofsupply='';
$state='';
if(!$request->all()==Null) {
if(!$request->state==Null) {
$state=$request->state;
}
if(!$request->typeofsupply==Null) {
$typeofsupply=$request->typeofsupply;
}
$items = Postjob::where('state',$state)
->where('typeofsupply',$typeofsupply)
->get();
dd($items);
【问题讨论】:
-
如果您不希望 typeofsupply 成为查询的一部分,只需将
->where('typeofsupply',$typeofsupply)留在查询之外 -
@RiggsFolly 我想要两个都在我的查询中
-
为什么,任何行实际上在 typeofsupply 中都包含 NULL?
-
我正在处理此页面过滤器planet.solarmarkit.com/solar-jobs 如果用户可以在框上应用过滤器,则第二个框的值将返回 null