{"id":19379744,"url":"https://github.com/jhumanj/laravel-model-stats","last_synced_at":"2025-04-04T15:09:41.586Z","repository":{"id":48869126,"uuid":"377090229","full_name":"JhumanJ/laravel-model-stats","owner":"JhumanJ","description":"Model statistics dashboard for your Laravel Application","archived":false,"fork":false,"pushed_at":"2023-08-24T08:09:42.000Z","size":2827,"stargazers_count":242,"open_issues_count":4,"forks_count":19,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-28T14:06:38.846Z","etag":null,"topics":["dashboard","eloquent-models","hacktoberfest","laravel","statistics"],"latest_commit_sha":null,"homepage":"","language":"Vue","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JhumanJ.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"JhumanJ"}},"created_at":"2021-06-15T08:25:32.000Z","updated_at":"2025-02-27T10:58:09.000Z","dependencies_parsed_at":"2024-06-20T21:59:36.635Z","dependency_job_id":"81cb4e7c-7a81-4308-8c0a-102177a5727a","html_url":"https://github.com/JhumanJ/laravel-model-stats","commit_stats":{"total_commits":44,"total_committers":7,"mean_commits":6.285714285714286,"dds":0.7272727272727273,"last_synced_commit":"88a47ed2a9dd784f2e4d70f30cf103d50bac5d0b"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JhumanJ%2Flaravel-model-stats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JhumanJ%2Flaravel-model-stats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JhumanJ%2Flaravel-model-stats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JhumanJ%2Flaravel-model-stats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JhumanJ","download_url":"https://codeload.github.com/JhumanJ/laravel-model-stats/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198463,"owners_count":20900080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dashboard","eloquent-models","hacktoberfest","laravel","statistics"],"created_at":"2024-11-10T09:11:17.624Z","updated_at":"2025-04-04T15:09:41.554Z","avatar_url":"https://github.com/JhumanJ.png","language":"Vue","funding_links":["https://github.com/sponsors/JhumanJ"],"categories":[],"sub_categories":[],"readme":"# Laravel Model Stats\nModel statistics dashboard for your Laravel Application\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/jhumanj/laravel-model-stats.svg?style=flat-square)](https://packagist.org/packages/jhumanj/laravel-model-stats)\n[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/jhumanj/laravel-model-stats/run-tests?label=tests)](https://github.com/jhumanj/laravel-model-stats/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/jhumanj/laravel-model-stats/Check%20\u0026%20fix%20styling?label=code%20style)](https://github.com/jhumanj/laravel-model-stats/actions?query=workflow%3A\"Check+%26+fix+styling\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/jhumanj/laravel-model-stats.svg?style=flat-square)](https://packagist.org/packages/jhumanj/laravel-model-stats)\n\n---\n\u003cimg style=\"margin:auto;\" src=\"https://i.ibb.co/hV6dt8L/Capture-d-e-cran-2021-09-11-a-10-54-59.png\" alt=\"Screenshot of sample dashboard\" border=\"0\"\u003e\n\nThis Laravel packages gives you a statistic dashboard for you Laravel application. Think of it as a light version of \n[Grafana](https://grafana.com/), but built-in your Laravel application, and much easier to get started with. \nNo code knowledge is required to use Laravel Model Stats, users can do everything from the web interface. It also \noptionally supports custom-code widgets, allowing you to define your widget data with\ncode, just like you would do with tinker.\n\n---\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require jhumanj/laravel-model-stats\n```\n\nYou can install the package and run the migrations with:\n\n```bash\nphp artisan model-stats:install\nphp artisan migrate\n```\n\n\n## Available No-Code Widgets\n\nDifferent type of widgets (daily count, daily average, etc.) are available. When creating a widget,\nyou choose a Model, an aggregation type and the column(s) for the graph. You can then resize and move the widgets around on your dashboard.\n\nThe aggregation types currently available:\n- Daily Count (Number of records per day during selected period).\n- Cumulated Daily Count (Cumulated Total record count during selected period).\n- Period Total (Number of new records during selected period).\n- Group By Count (Count per group for a given column during selected period).\n- ... (more to come soon)\n\nFor each widget type, date can be any column: `created_at`,`updated_at`,`custom_date`.\n\n## Custom Code Widgets\n\nYou can also use custom code widgets, allowing you to define your widget data with\ncode, just like you would do with tinker.\n\nYour code must define a `$result` variable containing the data to return to the choosen chart. You can use the `$dateFrom` and `$dateTo` variable.\n\nExample custom code for a bar chart:\n\n```php \n$result = [\n    'a' =\u003e 10,\n    'b' =\u003e 20\n];\n```\n\n### Custom Code Setup\n🚨 Using the custom code feature against a production database is a HUGE risk 🚨\n\nAny malicious user with access to the dashboard,\nor any mistake can cause harm to your database. Do not do that. Here's a safe way to use this feature:\n- Create a `read-only` database user with access to your database\n  - Here's how to create a read-only user for a PostgreSQL database: [PostgreSQL guide](https://tableplus.com/blog/2018/04/postgresql-how-to-create-read-only-user.html)\n  - Here's how to create a read-only user for a MySQL database: [MySQL guide](https://ubiq.co/database-blog/create-read-only-mysql-user/)\n- Add a readonly database connection to your `config/database.php` file\n  ```php\n  // in database.php\n  \n  'connections' =\u003e [\n  \n    // ... your other connections\n  \n     'readonly' =\u003e [\n            'driver' =\u003e 'pgsql',  // Copy the settings for the driver you use, but change the user\n            'url' =\u003e env('DATABASE_URL'),\n            'host' =\u003e env('DB_HOST', '127.0.0.1'),\n            'port' =\u003e env('DB_PORT', '5432'),\n            'database' =\u003e env('DB_DATABASE', 'forge'),\n            'username' =\u003e env('DB_USERNAME_READONLY', 'forge'), // User is changed here\n            'password' =\u003e env('DB_PASSWORD_READONLY', ''),\n            'charset' =\u003e 'utf8',\n            'prefix' =\u003e '',\n            'prefix_indexes' =\u003e true,\n            'schema' =\u003e 'public',\n            'sslmode' =\u003e 'prefer',\n        ],\n  ]\n- In your .env set the following:\n  ```dotenv\n    MODEL_STATS_CUSTOM_CODE=true\n    MODEL_STATS_DB_CONNECTION=readonly\n    DB_USERNAME_READONLY=\u003cusername\u003e\n    DB_PASSWORD_READONLY=\u003cpassword\u003e\n    ```\nThanks to this, the package will use the readonly connection when executing your code. \nNote that this a protection against mistakes, but not against malicious users. One can override this \nconnection in the custom code, so there are still some risks associate with using this feature in production.\nBe sure that your dashboard authorization is properly configured.\n\n### Disabling Custom Code\nYou may want to disable custom code widgets by setting the `MODEL_STATS_CUSTOM_CODE` env variable to `false`.\n\n## Dashboard Authorization\n\nThe ModelStats dashboard may be accessed at the `/stats` route. By default, you will only be able to access this \ndashboard in the local environment. Within your `app/Providers/ModelStatsServiceProvider.php` file, there is an \nauthorization gate definition. This authorization gate controls access to ModelStats in non-local environments. \nYou are free to modify this gate as needed to restrict access to your ModelStats installation: \n\n```php \n/**\n * Register the ModelStats gate.\n *\n * This gate determines who can access ModelStats in non-local environments.\n *\n * @return void\n */\nprotected function gate()\n{\n    Gate::define('viewModelStats', function ($user) {\n        return in_array($user-\u003eemail, [\n            'taylor@laravel.com',\n        ]);\n    });\n}\n```\n\n## Upgrading\n\nBe sure to re-publish the front-end assets when upgrading ModelStats:\n```\nphp artisan model-stats:publish\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits (Contributors)\n\n- [Julien Nahum](https://github.com/JhumanJ)\n\n## Inspiration \n- [Grafana](https://grafana.com/): for the dashboard/widget aspect\n- [Laravel/Telescope](https://github.com/laravel/telescope): for many things in the package structure (front-end, authorization...)\n- [Spatie/Laravel-Web-Tinker](https://github.com/spatie/laravel-web-tinker): for their web tinker implementation, which is used for custom code widgets\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhumanj%2Flaravel-model-stats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjhumanj%2Flaravel-model-stats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhumanj%2Flaravel-model-stats/lists"}