I have this two models below that have a 1 on 1 relationship. They worked like a charm but suddenly ( maybe because some updates in the database ( added 2 new columns )) it stopped working. I am getting the error only when I try to reach a payment that is part of a fare. For example.
$fare->payment->amount;
Gives an error: Trying to get property of non-object When I use a DD(); to debug I see the following show up. Pastebin
Does someone know what to do or how to solve this?
Below u can find the models
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;
}
}