Laravel过滤系统与多个复选框

时间:2017-03-17 23:42:17

标签: php laravel checkbox filter

我正在使用laravel 5.4,我想过滤搜索。它是我的前端

filter search multi checkbox option

我的代码看起来像这样

## Generate some data to approximate your picture
set.seed(42)
X10.Year.Standard.Deviation = c(rnorm(20,9.5,1), rnorm(20,8.2,0.8), 
    rnorm(15,8.4,0.6), rnorm(10, 8.2, 0.4), rnorm(2,8.0, 0.1))
Number.of.Managers.in.Portfolio = rep(seq(2,10,2), c(20,20,15,10,2))
LS10StDev = data.frame(Number.of.Managers.in.Portfolio,
    X10.Year.Standard.Deviation)

## Plot points
plot(LS10StDev, ylim=c(0,15), pch = 20, col='dark green')

## calculate quantiles and plot lines
Q25 = aggregate(LS10StDev$X10.Year.Standard.Deviation, 
        list(Number.of.Managers.in.Portfolio), quantile, 0.25)
Q50 = aggregate(LS10StDev$X10.Year.Standard.Deviation, 
        list(Number.of.Managers.in.Portfolio), quantile, 0.50)
Q75 = aggregate(LS10StDev$X10.Year.Standard.Deviation, 
        list(Number.of.Managers.in.Portfolio), quantile, 0.75)
lines(Q25, col="red")
lines(Q50, col="green")
lines(Q75, col="blue")

仅产生一个条目

2 个答案:

答案 0 :(得分:0)

您可以使用whereIn()采用不同的方法,假设您mark输入的是一组ID [1, 4, 8, 22]

public function filter(Request $request) 
{
    $features = Feature::when($request->has('mark'), function($query) use ($request) {
        return $query->whereIn('device_mark', $request->mark); //Assuming you are passing an array of IDs
    })->get();

    return $features;
}

when()关闭仅在您发送'标记'时执行。输入。没有的时候这样做会是这样的

public function filter(Request $request) 
{
    $features = [];

    if ( $request->has('mark') && $request->mark != '' ) {
        $features = Feature::whereIn('device_mark', $request->mark)->get();
    } else {
        $features = Feature::get();
    }

    return $features;
}

答案 1 :(得分:0)

非常简单的尝试ajax方法进行过滤搜索