akiyamaSM / larapoll

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

Add a custom user id from another newsletter user database table #120

Closed grafxflow closed 2 years ago

grafxflow commented 2 years ago

I have a database using 'users' and 'newsletter_subscribers' as separate tables.

I am sending the pole to the newsletter_subscribers and I can get the 'newsletter_subscribers_id'.

So for example I am sending a newsletter with the following url to the pole.

https://website.com/pole-id/user@newsletter.com

In the controller I am finding the newsletter user id with

$user_id = NewsletterSubscriber::select('id)->where('email', $newsletterEmail)->first();

How do I use this $user_id in the user_id column 'larapoll_votes' just like a guest ip?

grafxflow commented 2 years ago

Okay I have done a test and the only issue relates to the relationship column name 'newsletter_subscriber_id' instead of 'user_id'. Is there a way of changing 'newsletter_subscriber_id' to 'user_id' within the newsletter model or other?

Column not found: 1054 Unknown column 'larapoll_votes.newsletter_subscriber_id' in 'where clause' (SQL: select count(*) as aggregate from larapoll_options inner join larapoll_votes on larapoll_options.id = larapoll_votes.option_id where larapoll_votes.newsletter_subscriber_id is null and poll_id = 19)

grafxflow commented 2 years ago

Best solution is to fork the repo!