【发布时间】:2016-08-09 23:50:20
【问题描述】:
我想在我的表中为过期的“比赛”设置一个未来的时间戳。我可以毫无问题地输入时间,除非当我检索输入时,它似乎没有返回一个碳实例,而只是一个带时间的字符串?
public function store(ContestRequest $request)
{
$input = Request::all();
// Set the 'owner' attribute to the name of the currently logged in user(obviously requires login)
$input['owner'] = Auth::user()->name;
// Set the enddate according to the weeks that the user selected with the input select
$weeks = Request::input('ends_at');
// Add the weeks to the current time to set the future expiration date
$input['ends_at'] = Carbon::now()->addWeeks($weeks);
Contest::create($input);
return redirect('contests');
}
这是我用来创建新比赛的,表格中的时间格式与 created_at 和 updated_at 字段完全相同。当我尝试以下操作时,它们似乎返回了一个 Carbon 实例:
$contest->created_at->diffForHumans()
为什么我没有返回碳实例?
我的迁移文件如下所示:
$table->timestamps();
$table->timestamp('ends_at');
【问题讨论】:
标签: php laravel schema eloquent