akiyamaSM / larapoll

A Laravel package to manage your polls
MIT License
260 stars 58 forks source link

Guest voters unable to vote after first vote cast #80

Closed mrwhale closed 5 years ago

mrwhale commented 5 years ago

Hey, thanks for the great plugin!

I hijacked another issue but I think it needs its own.

First issue is that I'm having the same one as https://github.com/akiyamaSM/larapoll/issues/79

I have the latest but without adding the Voter trait I get the issue referened in that issue

This is worked around by just adding the trait for the User model

The second issue I am having is that after the first vote is cast for a poll, subsequent visits to the poll show the results rather then the question to be able to vote.

I have tried from other devices from the server so the IP is different

Any advice on this? Let me know if you need me to provide anything. I have not modified any code from this plugin

akiyamaSM commented 5 years ago

Hello, Thanks @mrwhale for the issue and the interest. The Voter is no more needed for the Guests to vote. make sure to reinstall the package and install the dev-master version. for the second issue I'd love you to compare both the ip stocked in the database and the current ip you are using.

mrwhale commented 5 years ago

Hey @akiyamaSM

I started from scratch, using dev-master instead of 2.5 in my composer file

Now I seem to be getting a different error all together

Argument 1 passed to Inani\Larapoll\Helpers\PollWriter::draw() must be an instance of Inani\Larapoll\Poll, integer given, called in /code/poll/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 237

I am using this in my view {{ PollWriter::draw(1) }}

akiyamaSM commented 5 years ago

Hey @mrwhale Actually, there was some changes in the draw method with the #65 PR, now it accepts an instance of Poll, {{ PollWriter::draw(Poll::find(1)) }}. Actually I was thinking to make some changes to not break existing code.

mrwhale commented 5 years ago

That makes sense! I'll give that one a go then. Thanks for the help @akiyamaSM I'll let you know how it goes

akiyamaSM commented 5 years ago

Thanks for the feedback @mrwhale, I'll leave it open until you confirm that everything is okey.

mrwhale commented 5 years ago

Okay so i've managed to get this working how I need it to, but I've had to modify some of your src code directly. Is there an easy way to overwrite/modiy these, for example, the Voter trait, without modifying it under the vendor folder? Not sure If i should put this in a pull request, but I found a logic issue that I was running into

Line 61 of the Poll model return $this->canVisitorsVote === 1; It would always return that visitors could not vote and would just return the results to a guest.

I've modified it to be just return $this->canVisitorsVote

I've also changed the Guest model so the user id is the session token, rather then the IP address of the client. To make that work I had to also adjust the Voter trait, line 96 to be ->where('larapoll_votes.user_id', request()->session()->token() instead of request()->ip()

Again, thanks for this nice plugin - saved me many hours trying to make one myself :)

akiyamaSM commented 5 years ago

Hello @mrwhale, Actually you can override what you want. check out the link here https://stackoverflow.com/questions/28104574/strategy-to-override-a-class-in-a-library-installed-with-composer