Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取两个冒号之间的数据_Php_Laravel_Laravel 5_Controller_Eloquent - Fatal编程技术网

Php 获取两个冒号之间的数据

Php 获取两个冒号之间的数据,php,laravel,laravel-5,controller,eloquent,Php,Laravel,Laravel 5,Controller,Eloquent,我正在使用Laravel 5.5。 我有一个带有模型的表centrals 像这样的桌子 我的控制器 $from = $request->year_from; $to = $request->year_to; $month_from = $request->month_from; $month_to = $request->month_to; $param = $request->get('parameters_id'

我正在使用Laravel 5.5。
我有一个带有模型的表centrals 像这样的桌子

我的控制器

    $from = $request->year_from;
    $to   = $request->year_to;
    $month_from = $request->month_from;
    $month_to   = $request->month_to;
    $param = $request->get('parameters_id', []);

    $search = Centrals::whereIn('parameters_id', $param)
    ->where('type', 'Monthly')
    ->where('year', $from)
    ->whereBetween('months_id', [$month_from, $month_to])
    ->orderBy('year')
    ->get();
现在我如何获取数据 请求示例:

$request->year_from = 2016;
$request->month_from = 1; /* 1 =Jan*/
$request->year_from = 2018;
$request->month_from = 3; /* 3 =Mar*/

下面应该可以做到这一点:

$search = Centrals::whereIn('parameters_id', $param)
        ->where('type', 'Monthly')
        ->where(function($q) use ($yearFrom, $monthFrom) {
            $q->where('year', '>', $yearFrom);
            $q->orWhere(function($q2) use ($yearFrom, $monthFrom) {
                $q2->where('year', $yearFrom);
                $q2->where('month', '>=', $monthFrom);
            });
        })
        ->where(function($q) use ($yearTo, $monthTo) {
            $q->where('year', '<', $yearTo);
            $q->orWhere(function($q2) use ($yearTo, $monthTo) {
                $q2->where('year', $yearTo);
                $q2->where('month', '<=', $monthTo);
            });
        })->get();
$search=Centrals::其中('parameters_id',$param)
->其中('类型','每月')
->其中(函数($q)使用($yearFrom,$monthFrom){
$q->where('year','>',$yearFrom);
$q->orWhere(函数($q2)使用($yearFrom,$monthFrom){
$q2->其中('year',$yearFrom);
$q2->where('month','>=',$monthFrom);
});
})
->其中(功能($q)使用($yearTo,$monthTo){
$q->where('年','