模型类中未定义的索引错误

时间:2015-05-31 03:52:12

标签: laravel laravel-5

我在尝试登录时有时会收到此错误。间歇性的。

[2015-05-31 03:41:48] local.ERROR: exception 'ErrorException' with message 'Undefined index: interval' in /var/www/xxxx/app/Models/Person.php:44

型号:

class Person extends BaseModel
{
    protected $rules = array(
      'interval'  => 'required'
    );

    protected $appends = ['interval_formatted','buying_interval_formatted'];

    public function getIntervalFormattedAttribute()
    {
        return Self::formatIntervalFromSeconds($this->attributes['interval']);
    }

    public function getBuyingIntervalFormattedAttribute()
    {
        return Self::formatIntervalFromMinutes($this->attributes['buying_interval']);
    }
}

帮助将受到高度赞赏。

1 个答案:

答案 0 :(得分:4)

您为什么使用$this->interval?您应该使用$this->buying_intervalpreg_replace($patterns, "", $string, 1); 代替。