-
Notifications
You must be signed in to change notification settings - Fork 330
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
Checking if user owns a model via keys of a pivot table #603
Comments
So I created a policy class called |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good day @JosephSilber, I got started with bouncer fairly recently and its a really great tool. It has really been helpful.
So lately I've been trying to implement something, I've got this user table and a business table, a single owner can own one or multiple businesses and a single business can be owned by one or multiple owners, so basically the relationship between these two tables is "many to many relationship". So I've got this pivot table that maps businesses to users and in my
Business.php
andUser.php
Models I've set up the relationships with theBelongsToMany()
method.Now, my question is, is their anyway for Bouncer to check if a Business model is owned by a given User, given that their is no
user_id
column on the business table, this would be impossible with something likeBouncer::can($ability, $business)
, so Is their a way I could do this, by let's say passing the pivot table and the corresponding keys to a method?I've tried using the
Bouncer::ownedVia()
method and passed in a callback function that checks if a user owns a business and so on, but I honestly want to know if their is a better way for this.The text was updated successfully, but these errors were encountered: