Mohammad Alfaz
Mohammad Alfaz

Reputation: 152

How to count visitors of my website in Laravel 5?

I am new to Laravel 5.

I want to count the number of visitor of my website. I already followed this steps in laravel visitors counter but it did not work.

Is there any other solution for this problem?

Upvotes: 1

Views: 11833

Answers (2)

Mahedi Hasan
Mahedi Hasan

Reputation: 1068

public function post(post $post)
	{   
		$key = 'myblog'.$post->id; 
		if (!Session::has($key)) {
	       $post->increment('view_count');
	       Session::put($key , 1);
		}

	
		 return view('frontend.post.show',compact('post'));
	}
  

Upvotes: 0

Jaymin Panchal
Jaymin Panchal

Reputation: 2856

Just use this library it provides lot of option for Tracking

https://github.com/antonioribeiro/tracker

Just install the dependency

composer require pragmarx/tracker

Add the service provider to your app/config/app.php:

'PragmaRX\Tracker\Vendor\Laravel\ServiceProvider',

Add the alias to the facade on your app/config/app.php:

'Tracker' => 'PragmaRX\Tracker\Vendor\Laravel\Facade',

Upvotes: 5

Related Questions