jacobcyl/laravel-counter

查看和点赞计数器

2.1.4 2016-06-03 09:13 UTC

This package is not auto-updated.

Last update: 2024-09-23 12:57:44 UTC


README

composer require jacobcyl/view-counter:^2.0

配置

添加提供者

    Jacobcyl\ViewCounter\ViewCounterServiceProvider::class,

发布配置文件和迁移文件

    php artisan vendor:publish 
    php artisan migrate

在模型中添加 "use ViewCounterTrait;"

    $model->view()

##编辑 app/Console/Kernel.php 文件的 schedule 方法,添加 counter:sync 命令

    protected function schedule(Schedule $schedule)
    {
        $schedule->command('counter:sync')->dailyAt('23:50');
    }

运行 crontab -e 然后添加以下内容

* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1

##命令将数据同步到数据库

php artisan counter:sync

初始化指定模型的视图计数器

php artisan counter:view product 100 --action=plus // the specified product increased by 100 views