Mor*_*ahi 2 php laravel php-carbon laravel-5 laravel-5.3
我需要更改一个帖子 created_at,因为我根据 created_at 向本月创建的帖子发送短信。当我尝试使用此 created_at 时不会改变值!
public function Controller(Posts $post){
$post->update(['created_at'=>Carbon::today()]);
}
Run Code Online (Sandbox Code Playgroud)
created_at通常不会像那样分配质量。您可能需要将其添加到模型的$fillable属性中Post,例如:
protected $fillable = [...., 'created_at'];
Run Code Online (Sandbox Code Playgroud)
请注意,正如其他人指出的那样,Carbon::today()这似乎不是正确的使用方法 - 它应该可以工作,但会给您一个午夜时间。你可能想要Carbon::now(),如果你真的想要一个准确的时间戳。