Vijayanand Premnath
Vijayanand Premnath

Reputation: 3605

Laravel view count increments even with session

My view count still increments even though I have session can any one tell what is wrong with my code?

if(! ( Session::get($id) == $id)){
        Post::where('id', $id)->increment('view_count');
        dd('added count');
        Session::put('id', $id);
      }

The id is the blog->id

Upvotes: 0

Views: 1238

Answers (1)

Shalu Singhal
Shalu Singhal

Reputation: 563

Your code should be

if(! ( Session::get('id') == $id)){
    Post::where('id', $id)->increment('view_count');
    dd('added count');
    Session::put('id', $id);
  }

change Session::get($id) to Session::get('id')

Upvotes: 1

Related Questions