-
Notifications
You must be signed in to change notification settings - Fork 104
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
Adding ability to send IP address from API routes #119
Conversation
Merge latest stable version branch into master
Codecov Report
@@ Coverage Diff @@
## 2.x #119 +/- ##
============================================
- Coverage 98.51% 98.16% -0.36%
- Complexity 105 106 +1
============================================
Files 11 11
Lines 270 272 +2
============================================
+ Hits 266 267 +1
- Misses 4 5 +1
Continue to review full report at Codecov.
|
@@ -49,7 +49,7 @@ public function getUniqueViewsCount($viewable, $period = null): int; | |||
* @param \Illuminate\Database\Eloquent\Model $viewable | |||
* @return bool | |||
*/ | |||
public function addViewTo($viewable): bool; | |||
public function addViewTo($viewable, $ip = ''): bool; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I don't have any plans for chaning this methods signature in v2.x
, I think it's better to replace $ip = ''
with $properties = []
or $data = []
, so if we want to add more options, they can pass it inside the same array instead of ...->addViewTo($post, false, $someVar, $someOtherVar)
.
@@ -28,8 +28,12 @@ class IpAddress | |||
* | |||
* @return bool | |||
*/ | |||
public function get() | |||
public function get($ip = '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to change this class.
@@ -73,9 +73,9 @@ public function getUniqueViews($period = null) : int | |||
* | |||
* @return bool | |||
*/ | |||
public function addView(): bool | |||
public function addView($ip = ''): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See first comment.
@@ -190,12 +190,12 @@ public function addViewTo($viewable): bool | |||
|
|||
$ignoredIpAddresses = Collection::make(config('eloquent-viewable.ignored_ip_addresses', [])); | |||
|
|||
if ($ignoredIpAddresses->contains($this->ipRepository->get())) { | |||
if ($ignoredIpAddresses->contains($this->ipRepository->get($ip))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do: $properties['ip'] ?? $this->ipRepository->get()
return false; | ||
} | ||
|
||
$visitorCookie = Cookie::get($cookieName); | ||
$visitor = $visitorCookie ?? $this->ipRepository->get(); | ||
$visitor = $visitorCookie ?? $this->ipRepository->get($ip); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same: $properties['ip'] ?? $this->ipRepository->get()
Fixes #82
If you are using this library as a backend server for native applications like Android or IOS you can send the IP address from the application through HTTP request like below:
$post->addView($ip);