我有这两个模型下面有1对1的关系。他们像一个魅力工作,但突然(可能是因为数据库中的一些更新(添加2个新列)),它停止工作。只有当我尝试达到属于票价一部分的付款时,我才会收到错误。例如。雄辩关系停止工作,不再工作
$fare->payment->amount;
给出一个错误:试图当我使用一个DD()来获得非对象 的属性;调试我看到下面的显示。 Pastebin
有人知道该怎么办或如何解决这个问题吗?
下面u能找到型号
class Fare extends Eloquent {
protected $table = 'fare';
public function payment()
{
return $this->hasOne('Payment');
}
public function email()
{
return $this->email;
}
public function getTimeagoAttribute()
{
$date = Carbon::createFromTimeStamp(strtotime($this->created_at))->diffForHumans();
return $date;
}
}
class Payment extends Eloquent {
protected $table = 'payment';
public function fare()
{
return $this->belongsTo('Fare');
}
public function status()
{
return $this->belongsTo('Status');
}
public function scopeApproved($query)
{
return $query->where('status', 1);
}
public function scopeDeclined($query)
{
return $query->where('status', 2);
}
public function getTimeagoAttribute()
{
$date = Carbon::createFromTimeStamp(strtotime($this->created_at))->diffForHumans();
return $date;
}
}
无关的你的问题,但默认你的'created_at'和'updated_at'列是Carbon对象。所以'getTimeagoAttribute()'可以简单地返回'$ this-> created_at-> diffForHumans()'! – Dwight 2014-09-28 11:30:00