I apologize for the title, I couldn't fit what I meant in it.
Almost every single Laravel tutorial I watch they all portray "if someone has access to a route... they have access to the route", and that makes sense, to a point. Let's take a SaaS for example though.
A User subscribes to Product(s). When I say "subscribe/subscription", I do not mean Laravel subscription functionality.
Those Product(s) are associated with locations. For simplicity sake let's say it's a postal code.
So in a pure PHP/MySQL setup I'd have at minimum 3 tables, presumably 4 though.
If 3 tables:
user - id, first_name, last_name, etc (PK id)
product - id, name, etc (PK id)
user_product - user_id, product_id, postal_code (FK user_id, FK product_id, PK user_id & product_id)
If 4 tables which is what I currently do:
user - id, first_name, last_name, etc (PK id)
product - id, name, etc (PK id)
user_product - id, user_id, product_id (PK id, FK user_id, FK product_id)
product_location - id, postal_code (PK id, FK user_product_id)
So in Laravel, I believe I'm at 2 Models so far, User and Product? User would have methods for fetching Products, Product would have methods for fetching locations, correct?
Currently, (again pure PHP/MySQL) when a client accesses /route/90210 (90210 is the postal code say) I first check if the client has a subscription to 90210 and then I handle the fetching of the 90210 data if that condition passes, otherwise return unauthorized.
Now, as I opened, in every tutorial /route/90210 would be considered "they have a subscription, let the request through". I'm curious though, in Laravel I don't believe it would be "proper" to do my existing code check of fetching of their subscriptions, if 90210 exists in their product subscriptions array of locations, now fetch the results for 90210. I'm unsure how you would go about using models to eloquently (no pun intended and no reference to eloquent) handle that checking.
I would imagine in the /route controller I would do something like:
if ($user->hasSubscription('ProductA')->hasLocation(90210)) { //return the data } return false;
^ Logically, the above is saying "If the User has a subscription to ProductA and that subscription has a location of 90210... conditional passes.