Php 未找到列:laravel雄辩关系中的1054未知列
我试图在当前时间戳上计算homecourt上的日程安排数,现在我在homecourt、userhomecourt和schedule之间的laravel中尝试了Php 未找到列:laravel雄辩关系中的1054未知列,php,laravel,eloquent,laravel-5.4,Php,Laravel,Eloquent,Laravel 5.4,我试图在当前时间戳上计算homecourt上的日程安排数,现在我在homecourt、userhomecourt和schedule之间的laravel中尝试了hasManyThrough,但出现了此错误 SQLSTATE[42S22]: Column not found: 1054 Unknown column 'timeFrom' in 'where clause' (SQL: select count(*) as aggregate from `tblHomeCourts` where `h
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)
我哪里错了?请改正一下
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');
}
}
您的
tblHomeCourts
表中是否有timeFrom
列?不,它在明细表中。请阅读此SQLSTATE[42S22]:未找到列:where子句中的1054未知列“timeFrom”(SQL:select count(*)作为从tblHomeCourts`wherehomeCourtId
=1和timeFrom
1496207469)的聚合)`它试图从tblHomeCourts
hmm中获取timeFrom
,我知道我的关系中有错误,你能纠正一下吗?请发布你的完整模型
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');
}
}