Comments (24)
supplying your own visitors IP address
Finally you understood me. Thanks mate.
from eloquent-viewable.
Strange. I tested it locally and it works properly. Do you get any errors?
from eloquent-viewable.
No errors, Just returning the post without incrementing the view on the views table. and that's my code:
public function show($id)
{
//Show a post in json through API
//Get a single post
$post = Post::findOrFail($id);
$post->addView();
//Return a single post as resource
return new PostResource($post);
}
from eloquent-viewable.
Does the view get stored after hitting the API route?
from eloquent-viewable.
No, it's not stored.
from eloquent-viewable.
I have the same problem 🤔 any news on this one? 🤔 i had to change back to using v1 for now. Still waiting for the fix.
from eloquent-viewable.
Indeed I Thought This Is Working On v2 As v1 But I Realize That It Not Hopefully There Is Some Progress 💯
from eloquent-viewable.
Hello, I did get the views to get saved in the views table properly with the API after I changed the visitor column's type to text because the token was too long. Edit: I don't understand why sometime I see ::1 in the visitor column of a view in the database instead of the token??
from eloquent-viewable.
Sorry for the delay. I'm pretty busy with school, jobs and sport right now.
Hey @Xoshbin, @Mohammad-Alavi , @zymawy and @MohamedElidrissi,
As @MohamedElidrissi already pointed out. Changing the type of the visitor
column to text
from string
will fix this issue probably.
Can one of you confirm this fix? Thanks!
from eloquent-viewable.
I released v2.4.3
with an updated views table stub.
from eloquent-viewable.
It's still not working for me!
The question is how does it determine the visitor column from API routes?
Let's say from web routes if it stores the IP address of the device or some token from session, what is going to store in the visitor column if it's from API routes? because I can pass and IP address if needed!
UPDATE:
It started working but the IP address is always 127.0.0.1, How can I pass the IP address as a parameter please?
from eloquent-viewable.
@Xoshbin I think that only happens in localhost, when I tried before it would show a long token. Edit: having to pass an ip address to the route is not convenient
from eloquent-viewable.
No I'm using it right now in production, every count is 127.0.0.1
from eloquent-viewable.
@Xoshbin but if your ip is 127.0.0.1 that means you're on the same network as the server?
from eloquent-viewable.
That's right, Because from API routes I don't send the IP address to this library so it doesn't know what's the IP address, so it adds 127.0.0.1. That's very logic, Think about it there is no way for this library to know the IP address of my Android application that's installed on somebody's device if I'm not sending the IP address to this library!
from eloquent-viewable.
@Xoshbin man I tested it and it does save some views with a token instead of ip, so that might be a bug
from eloquent-viewable.
@MohamedElidrissi I think you have tested it from browser, It's working if you open the post from browser and it saves a token. but test it from Postman and not from routes/web.php test it from routes/api.php please.
from eloquent-viewable.
@Xoshbin I can finally reproduce your issue. It works properly when commenting out the following if-statement inside the addViewTo method in ViewableService
:
// If ignore bots is true and the current viewer is a bot, return false
if ($ignoreBots && $this->crawlerDetector->isBot()) {
return false;
}
Edit: I think because of this line: https://github.com/JayBizzle/Crawler-Detect/blob/master/raw/Crawlers.txt#L798
Workaround would be allowing bots in development mode.
Edit: Yep that did the job for me.
from eloquent-viewable.
Please let me know if this was the solution!
from eloquent-viewable.
I hate to say that, but now from postman it's storing a token, but from smartphone application which Im using Volley library for Android HTTP networking it's still 127.0.0.1
from eloquent-viewable.
What doesRequest::ip();
return on a test api route?
from eloquent-viewable.
It looks like it's returning 127.0.0.1. I think there should be away to pass the IP address as a parameter to this library, before this library I was using another library it had the same issue so I was grabbing the IP address from the mobile device and sending it to the library through HTTP as a parameter.
$post->addView('192.168.10.15');
So I don't know how exactly this library is working and I don't know how this library is determining the IP address of the smartphone device or making some tokens because it's restful API's, not browsers. from API's you have to send these things manually I think!
from eloquent-viewable.
No need of passing it through. You can bind your own implementation of the IpAddress class to the container.
// App\Providers\AppServiceProvider.php
use CyrildeWit\EloquentViewabe\Support\IpAddress;
use App\Resolvers\IpAddressResolver;
$this->app->bind(IpAddress::class, IpAddressResolver::class);
// App\Resolvers\IpAddressResolver.php
class IpAddressResolver
{
public function get()
{
return \Request::ip();
}
}
from eloquent-viewable.
I have added a pull request, that's the only way worked for me and I think it's the only way to make it work with API's. I hope would be a helpful PR #119
from eloquent-viewable.
Related Issues (20)
- give point to post author on unique post view HOT 1
- how can I get user post view count HOT 1
- how to get total number of views of all posts HOT 1
- Getting Column not found when using ->orderByViews() HOT 10
- Laravel 9 support HOT 6
- `touch` the parent timestamp if the view has been recorded HOT 3
- Error : Cannot record a view for a viewable type HOT 1
- How to add some fields to table views HOT 1
- cannot record new views instance HOT 2
- Is there a way to record a view on cyrildewit / eloquent-viewable with the user_id not just the viewable_id HOT 1
- local.ERROR: Undefined index: lifetime_in_minutes
- Class "Period" not found HOT 2
- How can I check if an auth user or a visitor has already viewed a post? HOT 4
- Laravel 10 Support HOT 2
- PHP 8.2 support HOT 2
- CyrildeWit\EloquentViewable\Views::forViewable(): Argument #1 ($viewable) must be of type HOT 1
- How to extend the package to also count other things HOT 2
- User show the post twice HOT 1
- [Question] Seperate records by type
- Sort OutType Error:
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eloquent-viewable.