未找到列:1054 laravel雄辩关系中的未知列

时间:2017-05-31 05:56:49

标签: php laravel eloquent laravel-5.4

我试图在当前时间戳上计算主场的时间表数量,现在我在主场,用户家庭,时间表之间的laravel中尝试了hasManyThrough但是得到了这个错误

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'timeFrom' in 'where clause' (SQL: select count(*) as aggregate from `tblHomeCourts` where `homeCourtId` = 1 and `timeFrom` <= 1496207469 and `timeTo` > 1496207469)

我在HomeCourt模型中有这些关系

public function playerCount()
{
    return $this->hasManyThrough(Schedule::class,UserHomeCourt::class,'homeCourtId','userHomeCourtId','homeCourtId');
}

我错在哪里?请纠正它。

class HomeCourt extends Model
{
    protected $table = 'tblHomeCourts';
    protected $primaryKey = 'homeCourtId';
    protected $appends = ['homeCourtProfilePicUrl'];
    public static $snakeAttributes = false;
    protected $fillable = [
        'homeCourtName',
        'cityId',
        'homeCourtProfilePic',
        'gameType',
        'courtType',
        'numberOfCourts',
        'lights',
        'membershipStatus',
        'dayCost',
        'address',
        'lat',
        'long',
        'userId',
        'homeCourtStatus',
    ];
    protected $hidden = ['homeCourtProfilePic', 'created_at', 'updated_at', 'homeCourtStatus', 'userId', 'cityId'];

    public function getHomeCourtProfilePicUrlAttribute()
    {
        return ($this->attributes['homeCourtProfilePic'] != "" || $this->attributes['homeCourtProfilePic'] != null) ? Constant::HOMECOURT_PROFILE_URL . $this->attributes['homeCourtProfilePic'] : null;
    }

    /*relation for there now*/
    public function user()
    {
        return $this->belongsTo(User::class, 'homeCourtId', 'homeCourtId');
    }

    /*player count*/
    public function playerCount()
    {
        return $this->hasManyThrough(Schedule::class,UserHomeCourt::class,'homeCourtId','userHomeCourtId','homeCourtId');
    }


}

0 个答案:

没有答案