| Package Data | |
|---|---|
| Maintainer Username: | jacobcyl |
| Maintainer Contact: | cyl.jacob@gmail.com (jacobcyl) |
| Package Create Date: | 2016-05-31 |
| Package Last Update: | 2016-06-03 |
| Home Page: | |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-30 03:05:24 |
| Package Statistics | |
|---|---|
| Total Downloads: | 681 |
| Monthly Downloads: | 1 |
| Daily Downloads: | 0 |
| Total Stars: | 1 |
| Total Watchers: | 2 |
| Total Forks: | 0 |
| Total Open Issues: | 0 |
composer require jacobcyl/view-counter:^2.0
add provider
Jacobcyl\ViewCounter\ViewCounterServiceProvider::class,
publish config file and migration files
php artisan vendor:publish
php artisan migrate
add "use ViewCounterTrait;" to your model
$model->view()
##add schedule task edit app/Console/Kernel.php file's schedule method.add counter:sync command:
protected function schedule(Schedule $schedule)
{
$schedule->command('counter:sync')->dailyAt('23:50');
}
run crontab -e then add follow
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
##command synchronize data to the database
php artisan counter:sync
initialize view counter of specified model
php artisan counter:view product 100 --action=plus // the specified product increased by 100 views