cyrildewit / eloquent-viewable

Associate views with Eloquent models in Laravel
MIT License
803 stars 104 forks source link

give point to post author on unique post view #260

Closed Elusoji closed 1 year ago

Elusoji commented 2 years ago

I am using ur package to record post view with this package https://github.com/ansezz/laravel-gamify

so I will like to give author point when there post is viewed but the view must be unique in order to give point

example when a user view the author post give author point , but when that same user view the same post again don't give author point


public function mount(Post $post)
{
   $this->post = $post
   views($post)->cool down(24)->record();

 if(views($post)->count()> 1 ){
       $point = Point::find(2);
      $this->post->user->achievePoint($point);
   }
}
cyrildewit commented 2 years ago

I think the API of this package could have some improvements, since I don't provide a way of accessing this information after a view record was made.

Your solution is more practical, but I think you should use the returned value from the ->record() method instead of the extra count query. It returns a boolean.