当新用户注册到我的应用程序时,我正在尝试在包含时间戳列的注册表中创建新行。
我收到以下错误:
ErrorException in Registration.php line 111: Trying to get property of non-object
in Registration.php line 111
at HandleExceptions->handleError('8', 'Trying to get property of non-object', '/app/Registration.php', '111', array('registration_time' => object(Carbon))) in Registration.php line 111
at Registration->setRegistrationTimeAttribute(object(Carbon)) in Model.php line 2863
at Model->setAttribute('registration_time', object(Carbon)) in Model.php line 422
AuthController.php(控制器)
$registration = Registration::create([
'business_id' => '1',
'registration_time' => \Carbon\Carbon::today()->addDays(3)->addHours(10)->toDateTimeString()
]);
控制器中的registration_time回声
2016-02-12 10:00:00
Registration.php(model)第111行
public function setRegistrationTimeAttribute($registration_time)
{
$this->attributes['registration_time'] = Carbon::createFromFormat('Y-m-d H:i', $registration_time, \Auth::user()->timezone)->setTimezone('UTC');
}
我不明白,类似的代码在我的RegistrationTableSeeder中有效,我的模型接受这种格式。
'registration_time' => \Carbon\Carbon::now()->addDays(3)->addHours(1)->toDateTimeString(),