我想强制两篇文章之间1分钟的差距,由同一用户张贴。这是为了防止意外的双重发布,并希望减少垃圾邮件。两篇文章之间强制1分钟差距
现在我
public function canPostNewArticle()
{
$article = Article::where('user_id', $this->id)->latest()->first();
if ($article == null)
{
return true;
}
$date = $article->created_at->timestamp;
$currentTime = Carbon::now()->timestamp;
$diff = ($currentTime - $date)/60;
return $diff > 1;
}
我使用这个函数创建一个新的文章之前入住User
模型做这个。有一个更好的方法吗。