PHPackages                             mmehdizadeh/visitor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mmehdizadeh/visitor

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mmehdizadeh/visitor
===================

Laravel visitor

v1(1y ago)03MITPHPPHP &gt;=8.0

Since Oct 24Pushed 1y agoCompare

[ Source](https://github.com/mmehdizadeh/visitor)[ Packagist](https://packagist.org/packages/mmehdizadeh/visitor)[ Docs](https://github.com/mmehdizadeh/visitor)[ RSS](/packages/mmehdizadeh-visitor/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (3)Used By (0)

[![](resources/images/visitor.png?raw=true)](resources/images/visitor.png?raw=true)

Laravel Visitor
===============

[](#laravel-visitor)

This is a laravel package to extract and access visitors' information such as `browser`, `ip`, `device` and etc.

**In this package, you can recognize online users and determine if a user is online or not**

### Install

[](#install)

Via composer

```
composer require shetabit/visitor
```

### Configure

[](#configure)

If you are using Laravel 5.5 or higher then you don't need to add the provider and alias.

```
# In your providers array.
'providers' => [
    ...
    Shetabit\Visitor\Provider\VisitorServiceProvider::class,
],

# In your aliases array.
'aliases' => [
    ...
    'Visitor' => Shetabit\Visitor\Facade\Visitor::class,
],
```

Then, run the below commands to publish migrations and create tables

```
php artisan vendor:publish

php artisan migrate
```

### How to use

[](#how-to-use)

You can access to `visitor's information` using `$request->visitor()` in your controllers , and you can access to the visitor's information using `visitor()` helper function any where.

We have the below methods to retrieve a visitor's information:

- `device` : device's name
- `platform` : platform's name
- `browser` : browser's name
- `languages` : language's name
- `ip` : client's ip
- `request` : the whole request inputs
- `useragent` : the whole useragent
- `isOnline` : determines if current (or given) user is online

```
$request->visitor()->browser(); // firefox
$request->visitor()->visit($post); // create log for post
$request->visitor()->setVisitor($user)->visit($post); // create a log which says $user has visited $post
```

#### Store Logs

[](#store-logs)

You can create logs using the `visit` method like the below

```
visitor()->visit(); // create a visit log
```

use `Shetabit\Visitor\Traits\Visitable` trait in your models, then you can save visit's log for your models like the below

```
// or you can save log like the below
visitor()->visit($model);
// or like the below
$model->createVisitLog();

// you can say which user has visited the given $model
$model->createVisitLog($user);
// or like the below
visitor()->setVisitor($user)->visit($model);
```

Model views can be loaded using `visits` relation.

You can count model visits like the below

```
$model->visitLogs()->count();
```

unique users can be counted by their IP and by model.

```
// by ip
$model->visitLogs()->distinct('ip')->count('ip');

// by user's model
$model->visitLogs()->visitor()->count();
```

use `Shetabit\Visitor\Traits\Visitor` in your `User` class, then you can run below codes

```
$user->visit(); // create a visit log
$user->visit($model); // create a log which says, $user has visited $model
```

#### Retrieve and Determine Online users

[](#retrieve-and-determine-online-users)

use `Shetabit\Visitor\Traits\Visitor` in your `User` class at first.

Then you can retrieve online users which are instance of `User` class and determine if a user is online.

```
visitor()->onlineVisitors(User::class); // returns collection of online users
User::online()->get(); // another way

visitor()->isOnline($user); // determines if the given user is online
$user->isOnline(); // another way
```

#### Automatic logging

[](#automatic-logging)

Your application can store visitor's log automatically using `LogVisits` middleware.

Add the `Shetabit\Visitor\Middlewares\LogVisits` middleware if you want to save logs automatically.

The middleware will store logs for models which has binded in router (router model binding) and has used `Shetabit\Visitor\Traits\Visitable` trait.

Star History
------------

[](#star-history)

[![Star History Chart](https://camo.githubusercontent.com/5207c62f6a4f7d2386cddcf770ab3cb84f753a80d982533f064b203e444065b5/68747470733a2f2f6170692e737461722d686973746f72792e636f6d2f7376673f7265706f733d73686574616269742f76697369746f7226747970653d44617465)](https://star-history.com/#shetabit/visitor&Date)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance41

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 51.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

521d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/79e611f9c242e66b46fe187907d8198d940f82a2a3203f1f29e7cec7aed41a8d?d=identicon)[mmehdizadeh](/maintainers/mmehdizadeh)

---

Top Contributors

[![khanzadimahdi](https://avatars.githubusercontent.com/u/6291970?v=4)](https://github.com/khanzadimahdi "khanzadimahdi (30 commits)")[![3m1n3nc3](https://avatars.githubusercontent.com/u/52163001?v=4)](https://github.com/3m1n3nc3 "3m1n3nc3 (3 commits)")[![lloricode](https://avatars.githubusercontent.com/u/8251344?v=4)](https://github.com/lloricode "lloricode (3 commits)")[![mmehdizadeh](https://avatars.githubusercontent.com/u/26895519?v=4)](https://github.com/mmehdizadeh "mmehdizadeh (3 commits)")[![amirsadeghi1](https://avatars.githubusercontent.com/u/26359326?v=4)](https://github.com/amirsadeghi1 "amirsadeghi1 (2 commits)")[![mamad55](https://avatars.githubusercontent.com/u/5247083?v=4)](https://github.com/mamad55 "mamad55 (2 commits)")[![Linedev-Web](https://avatars.githubusercontent.com/u/42696701?v=4)](https://github.com/Linedev-Web "Linedev-Web (2 commits)")[![cyrildewit](https://avatars.githubusercontent.com/u/16477999?v=4)](https://github.com/cyrildewit "cyrildewit (2 commits)")[![mehrab-wj](https://avatars.githubusercontent.com/u/13809573?v=4)](https://github.com/mehrab-wj "mehrab-wj (1 commits)")[![roshedgostarandev1](https://avatars.githubusercontent.com/u/52368299?v=4)](https://github.com/roshedgostarandev1 "roshedgostarandev1 (1 commits)")[![mohamedsabil83](https://avatars.githubusercontent.com/u/10126040?v=4)](https://github.com/mohamedsabil83 "mohamedsabil83 (1 commits)")[![mokhosh](https://avatars.githubusercontent.com/u/6499685?v=4)](https://github.com/mokhosh "mokhosh (1 commits)")[![nabil12ful](https://avatars.githubusercontent.com/u/31300818?v=4)](https://github.com/nabil12ful "nabil12ful (1 commits)")[![potofcoffee](https://avatars.githubusercontent.com/u/1712532?v=4)](https://github.com/potofcoffee "potofcoffee (1 commits)")[![bramr94](https://avatars.githubusercontent.com/u/24361182?v=4)](https://github.com/bramr94 "bramr94 (1 commits)")[![buzzclue](https://avatars.githubusercontent.com/u/43321373?v=4)](https://github.com/buzzclue "buzzclue (1 commits)")[![itsnasser](https://avatars.githubusercontent.com/u/32999648?v=4)](https://github.com/itsnasser "itsnasser (1 commits)")[![kingispeak](https://avatars.githubusercontent.com/u/6312731?v=4)](https://github.com/kingispeak "kingispeak (1 commits)")[![rogermedico](https://avatars.githubusercontent.com/u/2758290?v=4)](https://github.com/rogermedico "rogermedico (1 commits)")

---

Tags

visitortrack laravel visitorstrace laravel visitorsparse laravel user agents

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/mmehdizadeh-visitor/health.svg)

```
[![Health](https://phpackages.com/badges/mmehdizadeh-visitor/health.svg)](https://phpackages.com/packages/mmehdizadeh-visitor)
```

###  Alternatives

[shetabit/visitor

Laravel visitor

565578.2k8](/packages/shetabit-visitor)[hisorange/browser-detect

Browser &amp; Mobile detection package for Laravel.

1.1k10.1M50](/packages/hisorange-browser-detect)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
