dongyied24121 2015-02-10 15:04
浏览 75
已采纳

语法错误,Laravel中的意外' - >'(T_OBJECT_OPERATOR)

In Laravel 4.2, I am getting the following error:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_PARSE)
syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ')' 

This error happens in class Recommendation, which provides static function 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;
    }

}

on this line

->join('sites', function($join) use ($user->id) {

I cannot understand, what's wrong with the query..

Structure of Recommendations table is

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]

and Sites table is

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]
  • 写回答

2条回答 默认 最新

  • douli1854 2015-02-10 15:10
    关注

    There is no variable $user available in function getRecommendations(), the function argument $userID is not used inside the function and the anonymous function uses $userID.

    The only conclusion is that the line should read:

    ->join('sites', function($join) use ($userID) {
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型