Laravel:columnize() 必须是数组类型,给定字符串,调用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29457020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:18:04  来源:igfitidea点击:

Laravel: columnize() must be of the type array, string given, called in

laravellaravel-4eloquentlaravel-5

提问by Virgil Cruz

I want to call this query instead of ID when updating a record, but im getting an error saying columnize() must be of the type array, string given, called in

我想在更新记录时调用这个查询而不是 ID,但我收到一个错误,说columnize() 必须是数组类型,给定字符串,调用

$user = Attendances::find(DB::raw('concat (firstname, " ",lastname)'), 'like', Input::get('student_name'))->where('section_name', 'like', Input::get('section_name'))->where('teacher_id', '=', Auth::user()->id)->where('subject_code', 'like', Input::get('subject_code'));

Pleae help :(

请帮忙:(

回答by lukasgeiter

The first method should be where()as well, because find()only works with primary keys. Also at the end should call get()or first()to execute the query:

第一种方法也应该如此where(),因为find()只适用于主键。最后还应该调用get()first()执行查询:

$user = Attendances::where(DB::raw('concat (firstname, " ",lastname)'), 'like', Input::get('student_name'))
       ->where('section_name', 'like', Input::get('section_name'))
       ->where('teacher_id', '=', Auth::user()->id)
       ->where('subject_code', 'like', Input::get('subject_code'))
       ->first();