Giter Club home page Giter Club logo

Comments (24)

Xoshbin avatar Xoshbin commented on May 18, 2024 1

supplying your own visitors IP address
Finally you understood me. Thanks mate.

from eloquent-viewable.

cyrildewit avatar cyrildewit commented on May 18, 2024

Strange. I tested it locally and it works properly. Do you get any errors?

from eloquent-viewable.

Xoshbin avatar Xoshbin commented on May 18, 2024

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.

cyrildewit avatar cyrildewit commented on May 18, 2024

Does the view get stored after hitting the API route?

from eloquent-viewable.

Xoshbin avatar Xoshbin commented on May 18, 2024

No, it's not stored.

from eloquent-viewable.

Mohammad-Alavi avatar Mohammad-Alavi commented on May 18, 2024

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.

zymawy avatar zymawy commented on May 18, 2024

Indeed I Thought This Is Working On v2 As v1 But I Realize That It Not Hopefully There Is Some Progress 💯

from eloquent-viewable.

 avatar commented on May 18, 2024

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.

cyrildewit avatar cyrildewit commented on May 18, 2024

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.

cyrildewit avatar cyrildewit commented on May 18, 2024

I released v2.4.3 with an updated views table stub.

from eloquent-viewable.

Xoshbin avatar Xoshbin commented on May 18, 2024

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.

 avatar commented on May 18, 2024

@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.

Xoshbin avatar Xoshbin commented on May 18, 2024

No I'm using it right now in production, every count is 127.0.0.1

from eloquent-viewable.

 avatar commented on May 18, 2024

@Xoshbin but if your ip is 127.0.0.1 that means you're on the same network as the server?

from eloquent-viewable.

Xoshbin avatar Xoshbin commented on May 18, 2024

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.

 avatar commented on May 18, 2024

@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.

Xoshbin avatar Xoshbin commented on May 18, 2024

@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.

cyrildewit avatar cyrildewit commented on May 18, 2024

@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.

cyrildewit avatar cyrildewit commented on May 18, 2024

Please let me know if this was the solution!

from eloquent-viewable.

Xoshbin avatar Xoshbin commented on May 18, 2024

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.

cyrildewit avatar cyrildewit commented on May 18, 2024

What doesRequest::ip(); return on a test api route?

from eloquent-viewable.

Xoshbin avatar Xoshbin commented on May 18, 2024

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.

cyrildewit avatar cyrildewit commented on May 18, 2024

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.

Xoshbin avatar Xoshbin commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.