I want to force a 1min gap between two article post by same user. This is to prevent accidental double post and hopefully reduce spam.
right now I am doing this.
in user model
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;
}
I am using this function to check before creating new article. Is there a better way to do this.
via Chebli Mohamed
 
Aucun commentaire:
Enregistrer un commentaire