我是Laravel的新手,正在爲我的練習開發小型應用程序。我正在做求職功能。這個錯誤給了我很多麻煩,並且讓我很困惑。獲取未定義的抵消:1 laravel
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);
}
,我沒有得到我在哪裏做錯了,所以從給定片斷的任何建議,並在代碼
可能重複[PHP:「注意:Undefined vari能夠「,」注意:未定義的索引「和」注意:未定義的偏移「](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef ) –
請在運行for循環前請var_dump full $ search_results,然後在您的問題 –