我想強制兩篇文章之間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
模型做這個。有一個更好的方法嗎。