Counting Views of Articles - development

Counting Views of Articles

I created a simple application that counts the views of an article. In the database articles table has a column view_count. Also I have a defined event & listener that increments view_count every time when some article is viewed:

The question, how to make update view_count , and store in database..?!

AppEvents ArticleViews.php:

class ArticleViewsextends Event
{
    use SerializesModels;

    public $article;

    public function __construct(Article $article)
    {
        $this->article = $article;
    }

    public function broadcastOn()
    {
        return [];
    }
}

AppListeners IncrementArticleViewsCounts.php:

class IncrementArticleViewsCounts
{
    public function __construct()  { }

    public function handle(ArticleViewsextends $event)
    {
        $event->article->increment('view_count');
    }
}

And in ArticleController.php@show:

$articles= new Scholarship();

Event::fire(new ArticleViewsextends ($scholarships));

parent::$data['articles'] = $articles->getAllActiveArticlesForFrontEnd(parent::$data['language']);

In views don’t count.



from Laravel Questions and Answers https://laravelquestions.com/php/counting-views-of-articles/
via Lzo Media

Comments

Popular posts from this blog

ng-show doesn’t work correct with value boolean

Using PHP and MySQL data to generate PDF letters like in MS Word mailmerge functionality - development

ng-include of inline SVG does not display gradient except in Chrome