Download the PHP package dericktan/counter without Composer
On this page you can find all versions of the php package dericktan/counter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package counter
Hit Counter for Laravel 5.*
Installation
Run the following command:
Add the following to your config\app.php
Service Providers
Add the following to your config\app.php
Facades
Then run the following:
Set Cookie Name in Laravel env Config file
How to Use
Regular pages
Just add Counter::showAndCount('home')
( for blades uses {{ Counter::showAndCount('home') }}
). Change home
to a unique name for the page you are working with.
Dynamic pages
For dynamic pages, such as user profiles, or job listings etc you may provide a dynamic element like this Counter::showAndCount('user-profile', $user->id)
( for blades use {{ Counter::showAndCount('user-profile', $user->id) }}
)
Change
user-profile
to a unique name for the page you are working with.
Number output is already formatted. So 3000 visitors will render as 3,000
If you have records on a page but do not want to count visiting the page displaying the records as a hit on the record itself then change showAndCount
to just show
. Example Counter::show('job-listings', $job->id)
( for blades use {{ Counter::show('job-listings', $job->id) }}
)
You may get all hits for every page on the entire site with Counter::allHits()
( for blades use {{ Counter::allHits() }}
). To specify a day constraint, like only all hits for the past 30 days then do Counter::allHits(30)
(for blades use {{ Counter::allHits(30) }}
).
If you would just like to process a hit for a page without displaying anything then just use Counter::count('user-profile', $user->id)
. Works the same as all previous examples for both static and dynamic pages, blade is the same syntax. Useful for counting hits for a page without letting everyone see.
Enjoy!
Extra
- Package influenced by: defuse/phpcount
- How this differs from: weboAp/Visitor
This package lets you see hit counts for specific pages/objects as well as an overall site hit count. It also uses a uniquely generated cookie (fallback to IP) to give a more accurate reading. Nice package for the pro-anonymous people :)
Pull requests are welcome.
All versions of counter with dependencies
illuminate/support Version ^7.0
illuminate/database Version ^7.0
php Version >=7.2
jaybizzle/crawler-detect Version 1.*