Download the PHP package ami-hp/laravel-eye without Composer

On this page you can find all versions of the php package ami-hp/laravel-eye. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-eye

Laravel-Eye

Total Downloads Latest Stable Version License

A Php >=7.2 Package for Laravel.

This Package is a combination of two visit counter packages :

It Stores Each Visit based on user's Cookie. The Idea is being able to Cache Visits to reduce queries. Using Cache is better for Websites with a little higher than normal traffic.

Storing Method Speed
Database Low
Cache:file Medium
Cache:redis High

NOTE : If you save a high amount of data in cache, memory WILL BE EXHAUSTED. The Limitation Depends on your memory but no more than 1 million is recommended to save in cache.

These paths are provided for you to store the Visits When User Comes to your Visitable Page:

And These paths are provided to get the Visits from your storage:

Install

NOTE : It is recommended to migrate the default jobs and __failed_jobs__ tables that come with a fresh laravel project, too.

Config

After Publishing the package files, you will have an eye.php file in your config folder.

  1. Here you can define the name of your visits table.

  2. To Prevent getting Memory Errors, You can specify the maximum amount of Visits saved in cache. after reaching to the maximum, all the Visits will be inserted to database. Also, you can change your cache key, too.

  3. A Cookie will be set for the user when arrives to your page. You can Change the key of your cookie anytime. The Expiration Time is set for 5 years, you can change that as well.

  4. The Package uses two packages to parse user agents: jenssegers/agent and ua-parser/uap-php . On default it is set for jenssegers. You Can Change it to UAParser.

  5. You can decide to store crawlers visits or not. The Package will use jaybizzle/crawler-detect to detect crawlers.

  6. If you wanted to use Jobs to increase speed in your inserts the package will do it for you. Feel free to turn it to false any time.

Migration


Usage

Step 1: Set Visit Data From Start

The Visit Model is connected to the visit table which is shown above It is possible to Set Data From Start To the end of the chained methods.

Example

Set Visitable Model

If you don't use this method, by default visitable model is set to be NULL.

Set Visitor Model

If you don't use this method, by default visitable model is set to be auth()->user().

Set Collection

If you don't use this method, by default it is set for NULL.

Step 2: Choose Your Storing Method

You can choose your storage, which is where you want to store your visits in.

Example

Store Visits in Database

Storing visits in database is a common way to store data. By using this method everytime a user visits, a query will be made to be inserting your data to database. By default, this method uses queue to insert data but, you can always turn it off by changing the value of queue to false in the config file eye.php.

Pros : Gaining More control over visits with Visit model being connected to database.

Cons : Interacting with database takes time. And if your website simultaneously has a lot of visitors it will slow your website down.

Store Visits in Cache

Using Cache as storage works as a bypass for inserting data to database. But you can hold the data in cache as long as you want. There is a Limit to the number of visits you can save, and it is in your control by changing cache.max_count in config file eye.php. After Reaching to maximum, the package will automatically push visits to database. Key name of cache is also there to be changed if you needed.

Store Visits in Redis

The only thing you should do is to change CACHE_DRIVER to redis so the package will use Redis through Cache. The storing method is still viaCache().

Step 3: Set Data via Storing Methods

You can also set data from this stage instead of setting it before choosing your storing method. there is no difference.

NOTE: These methods are included in an interface so, they work in all storing methods.

Example

Set Visitable Model

If you don't use this method, by default visitable model is set to be NULL.

Set Visitor Model

If you don't use this method, by default visitable model is set to be auth()->user().

Set Collection

If you don't use this method, by default it is set for NULL.

Step 4: Define Conditions

Record only Once

By using the method package will check if the user has a record stored or not. If the user had already visited the page so a new visit WILL NOT be recorded.

It works with the cookie that package set for user when enters the page, and will be stored as unique_id.

NOTE: You can change the key of cookie and expiration time in config file eye.php by changing cookie.key and cookie.expire_time.

Step 5: Record the Visit

In the end you can insert the Visit Model to database or Cache. The Structure is basically this:

It means that you can also set the visitable and visitor from this method.

Additional Examples


How To Retrieve Visits

You might want to list the Visits with details or just count them. It is all possible. You can do it for each storage separately or all together combined.

The Steps are very similar to Recording Steps.

How To Retrieve From Each Storage

If you needed to retrieve data from each storage individually, you just need to use their storing method.

NOTE: The Following Steps apply to all storing methods.

Step 1: Selecting the Data You Need

It works exactly like setting data.

Selecting Visitable or Url

If you pass a model to visitable methods, It will select the Visits with the visitable model. But if you don't, it will select the url that the route is in. It works for NULL too.

For Visitable:

Result:

For Url:

Result:

Sometimes you don't need to enable a where clause for your query. you can disable it by using visitable(false).

Selecting Visitor

It is possible if you wanted to fetch the Visits that a specific visitor made. And you can pass NULL as well.

The difference between this method and the one in record steps is that you need to turn $whereMode argument to true. otherwise it just sets visitor.

Result:

Selecting Collection

Result:

Step 2: Add More Conditions

Select Visits In a Period of time

The period() method passes a Period class as argument.

You can read all about this class in Cryildewit/Period

Result:

Select Visits with a Unique value

There can be multiple rows with the same value in a column. By default, the method uses unique_id column which is the cookie of user.

via Cache

Result:

via Database

The Problem is that it doesn't work the same for all storing methods. In viaCache it retrieves for both fetching Visits details and counting, but in viaDatabase it only works with counting.

Result:

Step 3: Fetch Data From Storage

Finally, you can retrieve data only by using count() or get()

The Structure is basically this:

Get creative with it.

Examples

How To Retrieve From Multiple Storages

When using cache, after reaching the maximum amount package will push visits to database. or maybe you accidentally used multiple storages. The package provides you methods to use multiple storing methods all at once.

Step 1: Select Storing Methods

Select All

It's very simple.

Step 2: Select Visit Models

Do it as if you're using storages individually. It works the same.

Select Visitable Model

Select Visitor Model

Select collection

Step 2: Add More Conditions

Select A Period of Time

Select Unique Values

By default, it is set for unique_id.

As mentioned before, it only works on counting for database.

Step 3: Retrieve Visits

Combine the previous methods and add get() or count().

Examples

How To Delete Visits

Sometimes you need to delete some recorded visits from your storages. This package provides you some methods to do it individually or delete them all at once.

NOTE: Unique method does not work here

Delete All

  • Step 1 : Select Storing Methods
  • Step 2 : Truncate

    Examples

Delete Selected Visits

Selecting visits work exactly like retrieving them.

Examples


How To Use Traits

You can also get visits data through you morphed models.

EyeVisitable Trait

Add EyeVisitable to your visitable model.

Observer

Visitable observer will monitor your model's activity so, when your model got (force) deleted visits gets deleted as well by this code:

Relations

In order to use eager loading you will need database relationships.

Usage examples:

As you know, morphMany relationships are related to database, so somehow we need to access cached visits as well. this method also has been added to trait to access cached visits more easily.

Usage examples:

EyeVisitor Trait

Add EyeVisitor to your visitor model. and the rest is similar to visitable trait.

Observer

Relations


All versions of laravel-eye with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
ext-json Version *
illuminate/cache Version ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0
illuminate/database Version ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0
illuminate/contracts Version ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0
illuminate/http Version ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0
illuminate/support Version ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0
nesbot/carbon Version ^2.0
jaybizzle/crawler-detect Version ^1.0
jenssegers/agent Version ^2.6
ua-parser/uap-php Version ^3.9
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ami-hp/laravel-eye contains the following files

Loading the files please wait ....