jeudi 31 août 2017

Laravel, force 1min gap between article post

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.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2wWIqWK
via IFTTT

Aucun commentaire:

Enregistrer un commentaire