在Laravel 4.2,我收到以下錯誤:語法錯誤,意外 ' - >'(T_OBJECT_OPERATOR)在Laravel
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_PARSE)
syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ')'
此錯誤類建議,提供靜態函數getRecommendations
class Recommendation extends Eloquent {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'recommendations';
public static function getRecommendations($userID) {
$recommendations = DB::table('recommendations')
->join('sites', function($join) use ($user->id) {
$join->on('sites.id', '=', 'recommendations.site_id');
$join->on('sites.owner', '=', DB::raw($userID));
})
->select('recommendations.id', 'recommendations.title', 'recommendations.body', 'recommendations.site_id', 'site.address')
->get();
return $recommendations;
}
}
發生
在這條線
->join('sites', function($join) use ($user->id) {
我不明白,這有什麼錯查詢..
的建議表結構是
id int(10) unsigned Autoincrement
title varchar(255)
body text
site_id int(10) unsigned
created_at timestamp [0000-00-00 00:00:00]
updated_at timestamp [0000-00-00 00:00:00]
和站點表是
id int(10) unsigned Автоматическое приращение
sitename varchar(255)
address varchar(64)
owner int(10) unsigned
created_at timestamp [0000-00-00 00:00:00]
updated_at timestamp [0000-00-00 00:00:00]
什麼是你的$用戶> ID?你沒有在任何地方使用它。你只有$ userID – Xyrus 2015-02-10 15:08:36
OMG ...看起來你是正確的......謝謝 – Lambrusco 2015-02-10 15:09:54
這就是發生了什麼whan你開始恐慌 – Lambrusco 2015-02-10 15:13:31