{"id":20428217,"url":"https://github.com/coderflexx/laravisit","last_synced_at":"2025-05-14T18:02:19.173Z","repository":{"id":38975465,"uuid":"456136458","full_name":"coderflexx/laravisit","owner":"coderflexx","description":"A package to keep track of your pages \u0026 understand your audience","archived":false,"fork":false,"pushed_at":"2025-05-12T07:44:09.000Z","size":208,"stargazers_count":423,"open_issues_count":1,"forks_count":27,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-12T08:55:48.866Z","etag":null,"topics":["analytics","eloquent","laravel","php"],"latest_commit_sha":null,"homepage":"https://coderflex.com/open-source/docs/laravisit/introduction","language":"PHP","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/coderflexx.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":"coderflex"}},"created_at":"2022-02-06T11:52:27.000Z","updated_at":"2025-05-12T07:44:07.000Z","dependencies_parsed_at":"2023-02-08T09:16:27.100Z","dependency_job_id":"c462425b-abc3-42e5-aa14-6fc7fb0e62d6","html_url":"https://github.com/coderflexx/laravisit","commit_stats":{"total_commits":117,"total_committers":8,"mean_commits":14.625,"dds":0.4786324786324786,"last_synced_commit":"0a96e5f368a483b48777e669c3ae944dcc737699"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderflexx%2Flaravisit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderflexx%2Flaravisit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderflexx%2Flaravisit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderflexx%2Flaravisit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coderflexx","download_url":"https://codeload.github.com/coderflexx/laravisit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253708811,"owners_count":21951058,"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":["analytics","eloquent","laravel","php"],"created_at":"2024-11-15T07:24:40.267Z","updated_at":"2025-05-14T18:02:18.882Z","avatar_url":"https://github.com/coderflexx.png","language":"PHP","readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"docs/images/Logo.png\" alt=\"Laravisit Logo\" width=\"300\"\u003e\n    \u003cbr\u003e\u003cbr\u003e\n\u003c/p\u003e\n\n[![The Latest Version on Packagist](https://img.shields.io/packagist/v/coderflexx/laravisit.svg?style=flat-square)](https://packagist.org/packages/coderflexx/laravisit)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/coderflexx/laravisit/run-tests.yml?branch=main\u0026label=tests)](https://github.com/coderflexx/laravisit/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/coderflexx/laravisit/phpstan.yml?branch=main\u0026label=code%20style)](https://github.com/coderflexx/laravisit/actions?query=workflow%3A\"Check+%26+fix+styling\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/coderflexx/laravisit.svg?style=flat-square)](https://packagist.org/packages/coderflexx/laravisit)\n\nA clean way to track your pages \u0026 understand your user's behavior\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require coderflexx/laravisit\n```\n\nYou can publish the config file with:\n\n```bash\n# linux\nphp artisan vendor:publish --provider=\"Coderflex\\\\Laravisit\\\\LaravisitServiceProvider\"\n\n# windows\nphp artisan vendor:publish --provider=\"Coderflex\\Laravisit\\LaravisitServiceProvider\"\n```\n\nthen, run database migration\n```bash\nphp artisan migrate\n```\n\nThis is the contents of the published config file:\n```php\nreturn [\n    /*\n    |--------------------------------------------------------------------------\n    | User Namespace\n    |--------------------------------------------------------------------------\n    |\n    | This value informs Laravisit which namespace you will be \n    | selecting to get the user model instance\n    | If this value equals to null, \"\\Coderflex\\Laravisit\\Models\\User\" will be used \n    | by default.\n    |\n    */\n    'user_namespace' =\u003e \"\\Coderflex\\Laravisit\\Models\\User\",\n];\n```\n\n\n## Usage\n\n### Use `HasVisits` Trait\n\nThe first thing you need  to do is, to use `HasVisits` trait, and implement `CanVisit` interface.\n\n```php\nnamespace App\\Models\\Post;\n\nuse Coderflex\\Laravisit\\Concerns\\CanVisit;\nuse Coderflex\\Laravisit\\Concerns\\HasVisits;\nuse Illuminate\\Database\\Eloquent\\Factories\\HasFactory;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Post extends Model implements CanVisit\n{\n    ...\n    use HasFactory;\n    use HasVisits;\n    ...\n}\n```\nAfter this step, you are all set, you can now count visits by using `visit` method\n\n```php\n$post-\u003evisit();\n```\n\nYou can chain methods to the `visit` method. Here are a list of the available methods:\n\n| METHOD      | SYNTAX      | DESCRIPTION | EXAMPLE     |\n| ----------- | ----------- | ----------- | ----------- |\n| `withIp()`      | string `$ip = null`       | Set an Ip address (default `request()-\u003eip()`)       | `$post-\u003evisit()-\u003ewithIp()`       |\n| `withSession()` | string `$session = null` | Set an Session ID (default `session()-\u003egetId()`) | `$post-\u003evisit()-\u003ewithSession()` |\n|`withData()` | array `$data` | Set custom data | `$post-\u003evisit()-\u003ewithData(['region' =\u003e 'USA'])` |\n| `withUser()` | Model `$user = null` | Set a user model (default `auth()-\u003euser()`) | `$user-\u003evisit()-\u003ewithUser()` |\n\n---\n\nBy default, you will have unique visits __each day__ using `dailyInterval()` method. Meaning, when the users access the page multiple times in a day time frame, you will see just `one record` related to them.\n\nIf you want to log users access to a page with different __timeframes__, here are a bunch of useful methods:\n\n| METHOD      | SYNTAX      | DESCRIPTION | EXAMPLE     |\n| ----------- | ----------- | ----------- | ----------- |\n| `hourlyInterval()` | `void` | Log visits each hour | `$post-\u003evisit()-\u003ehourlyIntervals()-\u003ewithIp();` |\n| `dailyInterval()` | `void` | Log visits each day | `$post-\u003evisit()-\u003edailyIntervals()-\u003ewithIp();` |\n| `weeklyInterval()` | `void` | Log visits each week | `$post-\u003evisit()-\u003eweeklyIntervals()-\u003ewithIp();` |\n| `monthlyInterval()` | `void` | Log visits each month | `$post-\u003evisit()-\u003emonthlyIntervals()-\u003ewithIp();` |\n| `yearlyInterval()` | `void` | Log visits each year | `$post-\u003evisit()-\u003eyearlyIntervals()-\u003ewithIp();` |\n| `customInterval()` | mixed `$interval` | Log visits within a custom interval | `$post-\u003evisit()-\u003ecustomInterval( now()-\u003esubYear() )-\u003ewithIp();` |\n\n### Get The Records With Popular Time Frames\nAfter the visits get logged, you can retrieve the data by the following method:\n\n| METHOD      | SYNTAX      | DESCRIPTION | EXAMPLE     |\n| ----------- | ----------- | ----------- | ----------- |\n| `withTotalVisitCount()` | `void` | get total visit count | `Post::withTotalVisitCount()-\u003efirst()-\u003evisit_count_total` |\n| `popularAllTime()` | `void` | get popular visits all time | `Post::popularAllTime()-\u003eget()` |\n| `popularToday()` | `void` | get popular visits in the current day | `Post::popularToday()-\u003eget()` |\n| `popularLastDays()` | int `$days` | get popular visits last given days | `Post::popularLastDays(10)-\u003eget()` |\n| `popularThisWeek()` | `void` | get popular visits this week | `Post::popularThisWeek()-\u003eget()` |\n| `popularLastWeek()` | `void` | get popular visits last week | `Post::popularLastWeek()-\u003eget()` |\n| `popularThisMonth()` | `void` | get popular visits this month | `Post::popularThisMonth()-\u003eget()` |\n| `popularLastMonth()` | `void` | get popular visits last month | `Post::popularLastMonth()-\u003eget()` |\n| `popularThisYear()` | `void` | get popular visits this year | `Post::popularThisYear()-\u003eget()` |\n| `popularLastYear()` | `void` | get popular visits last year | `Post::popularLastYear()-\u003eget()` |\n| `popularBetween()` | Carbon `$from`, Carbon `$to` | get popular visits between custom two dates | `Post::popularBetween(Carbon::createFromDate(2019, 1, 9), Carbon::createFromDat(2022, 1, 3))-\u003eget();` |\n\n## Visit Presenter\nThis package is coming with helpful decorate model properties, and it uses [Laravel Presenter](https://github.com/coderflexx/laravel-presenter) package under the hood.\n\n| METHOD      | SYNTAX      | DESCRIPTION | EXAMPLE     |\n| ----------- | ----------- | ----------- | ----------- |\n| `ip()` | `void` | Get the associated IP from the model instance | `$post-\u003evisits-\u003efirst()-\u003epresent()-\u003eip`|\n| `user()` | `void` | Get the associated User from the model instance | `$post-\u003evisits-\u003efirst()-\u003epresent()-\u003euser-\u003ename`|\n\n## Testing\n\n```bash\ncomposer test\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## Inspiration\n- [Codecourse Laravel Model Popularity](https://codecourse.com/courses/laravel-model-popularity)\n\n## Credits\n\n- [Oussama Sid](https://github.com/ousid)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","funding_links":["https://github.com/sponsors/coderflex"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderflexx%2Flaravisit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderflexx%2Flaravisit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderflexx%2Flaravisit/lists"}