未定义的偏移量:laravel 中的 0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41020256/
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 14:53:52 来源:igfitidea点击:
Undefined offset: 0 in laravel
提问by mySun
My framework is Laravel 5.2, There is no record in the database. But in this Site, it has error.
我的框架是Laravel 5.2,数据库中没有记录。但是在这个站点中,它有错误。
Error is:
错误是:
ErrorException in Collection.php line 1187:
Undefined offset: 0
Controller is:
控制器是:
public function index()
{
$comment = ProviderComment::GetComments($ID);
return $comment;
}
Model is:
型号为:
public function scopeGetComments($query, $vendorID)
{
$join = $query
-> join('couples', 'couples.id', '=', 'provider_comment.couple_id')
-> where('provider_comment.vendor_id', '=', $vendorID)
-> get();
return $join;
}
Where is my problem?
我的问题在哪里?
采纳答案by jeanj
Controller:
控制器:
public function index() {
$comment = ProviderComment::getComments($ID)->get();
return $comment; }
Model:
模型:
public function scopeGetComments($query, $vendorID)
{
return $query
->join('couples', 'couples.id', '=', 'provider_comment.couple_id')
->where('provider_comment.vendor_id', '=', $vendorID);
}
Don't use get()
directly on scopes.
不要get()
直接在作用域上使用。
More about scopes
有关范围的更多信息