laravel-ready / statistics
可用的 Laravel 统计包
v1.1.8
2024-01-18 06:42 UTC
Requires
- php: ^8.1 || ^8.0
- illuminate/support: ^10.0 || ^9.0
- laravel-ready/ultimate-support: ^1.1
- matomo/device-detector: ^6.2
Requires (Dev)
- mockery/mockery: ^1.5
- nunomaduro/larastan: ^2.5
- orchestra/testbench: ^8.0
- pestphp/pest: ^1.22
- pestphp/pest-plugin-laravel: ^1.4
- pestphp/pest-plugin-parallel: ^1.2
- phpstan/extension-installer: ^1.2
- phpstan/phpstan: ^1.10
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
README
📂 关于
可用的 Laravel 统计包...
📦 安装
通过 composer 获取
composer require laravel-ready/statistics
⚙️ 配置
php artisan vendor:publish --tag=statistics-config
迁移
# publish migrations php artisan vendor:publish --tag=statistics-migrations # apply migrations php artisan migrate --path=/database/migrations/laravel-ready/statistics
📝 使用
将 Statisticable
特性添加到您的模型中
use LaravelReady\Statistics\Traits\Statisticable; class Post extends Model { use Statisticable; }
然后调用 touch
或 hit
方法来运行统计机制
use LaravelReady\Statistics\Supports\Statistic; Statistic::touch($model); // process data then save it Statistic::hit($model); // just saves raw data without processing (then you can process it later with jobs)
访问统计数据
$stats = $model->load('statistics');
通过计划任务(或您可以使用 LaravelReady\Statistics\Jobs\ProcessStatistic
作业)处理统计数据
<?php namespace App\Console; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; class Kernel extends ConsoleKernel { /** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { $schedule->command('statistics:process')->everyMinute(); } ...
🐳 Docker 配置
如果您想使用 ip2location 数据库,可以使用 docker 镜像。
环境变量
在 .env
文件(您的 Laravel 项目)中定义您的环境变量
# ip2location IP2LOCATION_TOKEN={YOUR_TOKEN} IP2LOCATION_CODE=DB11-LITE IP2LOCATION_IP_TYPE=BOTH IP2LOCATION_MYSQL_PORT=1010 IP2LOCATION_MYSQL_HOST=127.0.0.1 IP2LOCATION_MYSQL_DBNAME=ip2location_database IP2LOCATION_MYSQL_USERNAME=admin IP2LOCATION_MYSQL_PASSWORD=secret
Docker Compose
在您的 Laravel 项目中创建 docker-compose.yml
文件
version: "3.8" services: # ip2location server ip2location_mysql: image: ip2location/mysql:latest container_name: ip2location_mysql restart: unless-stopped ports: - ${IP2LOCATION_MYSQL_PORT}:3306 environment: TOKEN: ${IP2LOCATION_TOKEN} CODE: ${IP2LOCATION_CODE} IP_TYPE: ${IP2LOCATION_IP_TYPE} MYSQL_PASSWORD: ${IP2LOCATION_MYSQL_PASSWORD} networks: - mysql_net networks: mysql_net: driver: bridge
运行 docker 容器
docker-compose up -d
然后等待 ip2location 数据库下载完成(这可能需要一些时间)。
⚓致谢
- 此项目由 packager 生成。