我试图获取日期和课程名称的值,但我收到了这些错误异常。环形:array:2 [▼ 0 => Collection {#284 ▼#items: array:3 [▼ 0 => {#277 ▼ +"date": "2018" } 1 => {#279 ▶} 4 => {#282 ▶}`` ] } 1 => Collection {#283 ▼ #items: array:2 [▼ 0 => {#280 ▼ +"id": 1 +"courseName": "newc1" } 1 => {#271 ▶} ] } ] //tried these @foreach ($result as $key=> $value) @foreach ($value as $val) {{$val->date}} @endforeach @endforeach //controller $data = array(); $date = db::table('students')->select('date')->get()->unique(); $course = db::table('courses')->select('id', 'courseName')->get(); array_push($data, $date, $course);需要遍历这些。而是得到了 ErrorException (E_ERROR) 未定义的属性:stdClass::$date
2 回答
慕娘9325324
TA贡献1783条经验 获得超4个赞
你必须控制数据库结果,如果它在日期选择上也可以为 laravel 使用 distinct() 和 get 必须在它之前的最后
//This
$date = db::table('students')->select('date')->get()->unique();
//To This
$date = db::table('students')->select('date')->distinct()->get();
if(!$date)
return $this->response;
//or
return false;
//更新
$course = DB::table('students')
->select('id','courseName', 'courses')
->groupBy('courses')//What ever you want to uniqe
->get();
对于返回视图示例,您必须自己更改
return $this->responseWithView("index //PAGE","success", ['courses' => $course,'anything' => $youwant]);
- 2 回答
- 0 关注
- 142 浏览
添加回答
举报
0/150
提交
取消