https://github.com/warcooft/shield-visitors
A lightweight profile visitor tracking system for CodeIgniter Shield, designed to monitor user profile visits similar to LinkedIn’s profile viewers feature.
https://github.com/warcooft/shield-visitors
codeigniter4 php8 shield
Last synced: 9 months ago
JSON representation
A lightweight profile visitor tracking system for CodeIgniter Shield, designed to monitor user profile visits similar to LinkedIn’s profile viewers feature.
- Host: GitHub
- URL: https://github.com/warcooft/shield-visitors
- Owner: warcooft
- License: mit
- Created: 2024-09-15T11:37:22.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-16T22:22:42.000Z (over 1 year ago)
- Last Synced: 2025-03-25T09:11:12.218Z (10 months ago)
- Topics: codeigniter4, php8, shield
- Language: PHP
- Homepage:
- Size: 16 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Profile Visitor Tracking System for CodeIgniter Shield
A lightweight profile visitor tracking system for CodeIgniter Shield, designed to monitor user profile visits similar to LinkedIn’s profile viewers feature.
# Install
Install easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities and always be up-to-date:
```
composer require aselsan/visitors
```
Once the files are downloaded and included in the autoload, run any library migrations to ensure the database is set up correctly:
```
php spark migrate --all
```
# Configuration
Add `HasVisitors` trait to your users model and initialize visitors with `initVisitors()` method.
```php
class ExampleUsersModel extends BaseModel
{
use HasVisitors;
// ...
protected function initialize()
{
$this->initVisitors();
}
// ...
}
```
And if you use Entity class, add `Visitable` trait to it:
```php
class ExampleUser extends Entity
{
use Visitable;
// ...
}
```
# Usage
### Visit a User
To record a visit to a specific user's profile:
```php
$users = auth()->getProvider();
$user = $users->find($id);
// Record a visit to this user
$user->visit();
```
### Get a User with Visitor Information
To retrieve a user along with their visitors:
```php
$users = auth()->getProvider();
$user = $users->withVisitors()->find($id);
// Get total number of visitors
$user->getSumVisitors();
// Get detailed visitor information
$user->visitors;
// or
$user->getVisitors();
```
## License
This project is licensed under the MIT License - see the [LICENSE](/LICENSE) file for details.