laravel-ready / statistics
Ready to use Laravel statistic package
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
📂 About
Ready to use Laravel statistic package...
📦 Installation
Get via composer
composer require laravel-ready/statistics
⚙️ Configs
php artisan vendor:publish --tag=statistics-config
Migrations
# publish migrations php artisan vendor:publish --tag=statistics-migrations # apply migrations php artisan migrate --path=/database/migrations/laravel-ready/statistics
📝 Usage
Add Statisticable
trait to your model
use LaravelReady\Statistics\Traits\Statisticable; class Post extends Model { use Statisticable; }
Then call touch
or hit
method to run statistic mechanism
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)
Access statistic data
$stats = $model->load('statistics');
Process statistic data with scheduled command (or you can use LaravelReady\Statistics\Jobs\ProcessStatistic
job)
<?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 Configs
İf you want to use ip2location database, you can use docker image.
Environment Variables
Define your environment variables in .env
file (your laravel project)
# 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
Create docker-compose.yml
file in your laravel project
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
Run docker containers
docker-compose up -d
Then wait for ip2location database to be downloaded (this may some time).
⚓Credits
- This project was generated by the packager.