enter image description hereenter image description hereI hope someone can help me. I came across a very complex Laravel query and I don't know how to get out of it. My problem is that in the database I would like to group a series of columns so that the results of these groups are unique because they are repeated and select data from other columns belonging to these groups e.g. warehouse column is repeated 3 times I would like it to be displayed once, listing all the warehouse audit dates in another column and the results of these dates in another column. I wrote like this but I don't get the result. Can anyone help me understand what I'm doing wrong, thank you very much.. I would like to get some kind of graph..

-oh my 天.

$audit = DB::table('esiti_audit')->where('employee', $name)
        ->select('master_zone', 'subarea', 'microarea')        
        ->groupByRaw('master_zone,subarea,microarea')
        ->orderByDesc('data_audit')->select('data_audit', 'esito')
        ->get();

推荐答案

在区域和天数内构建所需的 struct :

$audits = DB::table('esiti_audit')->select([
    'master_zone', 'subarea', 'microarea',
    'data_audit', 'esito'
  ])
  ->where('employee', $name)
  ->orderByDesc('data_audit')
  ->get()->toArray();

$data = [];

foreach($audits as $audit) {
  // build this into a key or nested arrays, up to the use case
  $areaKey = "{$audit['master_zone']}|{$audit['subarea']}|{$audit['microarea']}";

  $data[$areaKey][] = [
    'status' => $audit['esito'],
    'date' => $audit['data_audit']
  ];
}

// pass $data to your view and loop as @foreach($data as $area => $audits)

Laravel相关问答推荐

Inertia React中的错误文件上传更新

从8.0更新到10.0后,图像不再上传到存储

Laravel:在 PHPUnit 的覆盖率报告中包含文件夹(如果在 app/ 文件夹之外)?

如何通过单击进入 vs 代码中的类

Laravel查询多对多关系

所有 POST 请求上的 Laravel 4 CSRF

安卓 retrofit |发布自定义对象(将 json 发送到服务器)

在 Laravel 5 中扩展请求类

致命错误:找不到类App\Http\Controllers\Redirect

laravel 中的 Http Post 使用 fetch api 给出 TokenMismatchException

合并和排序两个 Eloquent 集合?

laravel 预期响应代码 250 但得到代码530

Laravel Passport Route [login] 未定义

使用模型工厂、一对一和一对多关系定义 Laravel 外键,而不创建不必要的模型

如何对模型执行删除操作?

Laravel Eloquent:计算总价的最佳方法

无法声明类 Controller,因为该名称已在使用中

Laravel 4:分析器在哪里?

如何访问 Laravel 集合中的第 n 个项目?

在 Laravel 中翻译特定语言