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

标签 php mysql laravel

在 Laravel 4.2 中,我收到以下错误:

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

这个错误发生在提供静态函数getRecommendations的Recommendation类中

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) {

我不明白,查询有什么问题..

Recommendations 表的结构是

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]

最佳答案

函数 getRecommendations() 中没有可用的变量 $user,函数参数 $userID 未在函数内部使用,并且匿名函数使用 $userID

唯一的结论是该行应该是:

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

关于php - 语法错误,Laravel 中意外的 '->' (T_OBJECT_OPERATOR),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28434971/

相关文章:

php - 从数据库中提取日期的分组

javascript - 来自使用 jQuery insideHTML 的页面的 PHP file_get_contents

javascript - HTML PHP onclick 只工作一次

php - 将复选框选定的行保存到php中的数据库中

php - 这个 MySQL 'insert' 语句有什么问题?

php - 使用 PDO 和 oops 选择查询

php - docker-compose php laravel - session 不会保持不变

MySql 更新并加入另一个表

php - 当我通过 Artisan 类运行时,sp​​atie/laravel-backup "mysqldump"无法识别

php - AWS SQS 错误 : SignatureDoesNotMatch HTTP error: 403