### Install Laravel Visitor Package Source: https://github.com/shetabit/visitor/blob/master/README.md Installs the 'shetabit/visitor' package using Composer. This is the initial step to integrate visitor tracking into your Laravel application. ```bash composer require shetabit/visitor ``` -------------------------------- ### Check Code Style with Composer Source: https://github.com/shetabit/visitor/blob/master/CONTRIBUTING.md This command checks the code style of the project against the PSR-2 standard. It requires Composer to be installed and configured for the project. ```shell composer check-style ``` -------------------------------- ### Fix Code Style with Composer Source: https://github.com/shetabit/visitor/blob/master/CONTRIBUTING.md This command automatically fixes code style issues according to the PSR-2 standard. It requires Composer to be installed and configured for the project. ```shell composer fix-style ``` -------------------------------- ### Access Visitor Information from Request in Laravel Source: https://github.com/shetabit/visitor/blob/master/README.md Demonstrates how to access visitor information directly from the request object in Laravel controllers using the installed package. It shows accessing browser information and logging visits. ```php $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 ``` -------------------------------- ### Publish Migrations and Run Migrations for Visitor Package Source: https://github.com/shetabit/visitor/blob/master/README.md Publishes the necessary migration files for the visitor package and then runs them to create the required database tables. This is essential for storing visitor-related data. ```bash php artisan vendor:publish php artisan migrate ``` -------------------------------- ### Log a Simple Visit Using Helper Function Source: https://github.com/shetabit/visitor/blob/master/README.md Creates a basic visit log using the global 'visitor()' helper function. This is a straightforward way to record a visit without associating it with a specific model or user initially. ```php visitor()->visit(); // create a visit log ``` -------------------------------- ### Log Visits for Users with Visitor Trait Source: https://github.com/shetabit/visitor/blob/master/README.md Demonstrates how to log visits when the 'Visitor' trait is used in a User model. This allows users to directly initiate visit logs, either for themselves or for specific models. ```php $user->visit(); // create a visit log $user->visit($model); // create a log which says, $user has visited $model ``` -------------------------------- ### Log Visits for Models with Visitable Trait Source: https://github.com/shetabit/visitor/blob/master/README.md Shows how to log visits for models that utilize the 'Visitable' trait. It covers creating visit logs for a model, associating them with a specific user, and directly calling a method on the model. ```php // 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); ``` -------------------------------- ### Configure Laravel Visitor Service Provider and Alias Source: https://github.com/shetabit/visitor/blob/master/README.md Registers the Visitor Service Provider and Alias in your Laravel application's configuration files. This step is necessary for versions prior to Laravel 5.5 or for manual configuration. ```php // In your providers array. 'providers' => [ ... Shetabit\Visitor\Provider\VisitorServiceProvider::class, ], // In your aliases array. 'aliases' => [ ... 'Visitor' => Shetabit\Visitor\Facade\Visitor::class, ] ``` -------------------------------- ### Count Model Visits and Unique Visitors Source: https://github.com/shetabit/visitor/blob/master/README.md Illustrates how to count total visits to a model and unique visits (by IP or by user model) using the package's relation capabilities. This helps in understanding engagement metrics. ```php $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(); ``` -------------------------------- ### Retrieve and Determine Online Users with Visitor Trait Source: https://github.com/shetabit/visitor/blob/master/README.md Shows how to retrieve a collection of currently online users and check if a specific user is online. This requires the 'Visitor' trait to be implemented in the User class. ```php 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 Visitor Logging with LogVisits Middleware Source: https://github.com/shetabit/visitor/blob/master/README.md Enables automatic logging of visitor activity by incorporating the 'LogVisits' middleware into the application's routing. This middleware automatically stores logs for models bound in the router that use the 'Visitable' trait. ```php // Add the Shetabit\Visitor\Middlewares\LogVisits middleware if you want to save logs automatically. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.