dongsuo0517 2017-02-04 10:33
浏览 39
已采纳

获取未定义的偏移量:laravel中为1

I am new to Laravel and was developing small application for my practise. I am doing job search functionality. This error giving me alot trouble and confuses me alot.

public function job_search(Request $request) {
    $search_skill_set = $request->job_skills;
    $search_results = JobPost::whereRaw('FIND_IN_SET(?, job_skills)', $search_skill_set)
        ->get()
        ->toArray();

    for ($i = 0; $i < count($search_results); $i++) {
        $department_id = (int)$search_results[$i]['department_name'];
        $department_name = Department::select('department_name')
            ->where('id', '=', $department_id)
            ->get()
            ->toArray();

        // the next statement raises an Undefined:offset 1 error
        $search_results[$i]['department_name_info'] = $department_name[$i]['department_name'];
    }
    var_dump($search_results);
}

I am not getting where am i doing wrong, so any suggestion from given snippet and any modification in the code

  • 写回答

2条回答 默认 最新

  • doubi5127 2017-02-04 10:39
    关注

    change this line:

     $search_results[$i]['department_name_info'] = $department_name[$i]['department_name'];
    

    to

     $search_results[$i]['department_name_info'] = $department_name[0]['department_name'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 GD模块安装出错,libgd无法正常安装
  • ¥20 求有缘人帮我把笛卡尔坐标系转换为经纬度 有偿
  • ¥15 vue2中使用计算属性
  • ¥50 远程桌面打开Mastercam、没有许可证、物理机打开正常
  • ¥15 ubuntu安装gdal后java读取tif文件报错
  • ¥15 请问lammps怎么做两种金属连接的原子浓度分布图
  • ¥15 求jacquard数据集
  • ¥15 w10部分软件不能联网
  • ¥15 关于安装hbase的问题(操作系统-windows)
  • ¥15 novnc连接pve虚拟机报错安全协议不支持262