Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same result #2

Open
FayzullaKhodja opened this issue Oct 6, 2015 · 5 comments
Open

Same result #2

FayzullaKhodja opened this issue Oct 6, 2015 · 5 comments

Comments

@FayzullaKhodja
Copy link

Hi, your counter show the same result in foreach. I use Counter::show('user-profile', $user->id), it gets first result in foreach

@camperro
Copy link

I have the same problem. I count when users see throw route "post/post_id"

when i list in another page to show all post and its counter i have the same result for all.

@rafalradomski
Copy link

@Kryptonit3 I have the same problem.

@Kryptonit3-zz
Copy link
Owner

So for posts you are counting with Counter::count('post', $post->id); when viewing the actual post. (remember, for dynamic pages the counter identifier needs to be unique from other pages. so you use your identifier and pass in the unique value for this page).

Then when you show the lists of posts with their views I assume you are doing this:

$posts = App\Post::all();

return view('all-posts', compact('posts'));

then in blade

@foreach($posts as $post)
    <li> this is a post - View Count: {{ Counter::show('post', $post->id) }}</li>
@endforeach

@ferjflores
Copy link

Hi, same problem here (Laravel v5.1.29), i did try as suggested @Kryptonit3, show the same result in the foreach.

@Roos12005
Copy link

I think it might work :D
I try to edit \vendor\kryptonit3\counter\src\Counter.php
by changing function private static function createPageIfNotPresent($page)
from

private static function createPageIfNotPresent($page)
{
    if (!isset(self::$current_page)) {
        self::$current_page = Page::firstOrCreate([
            'page' => $page
        ]);
    }

    return self::$current_page;
}

to

private static function createPageIfNotPresent($page)
{
    return self::$current_page = Page::firstOrCreate(['page' => $page]);
}

kanasite added a commit to kanasite/Counter that referenced this issue Sep 5, 2016
Fix bug as suggested by Roos Kryptonit3-zz#2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants