reviewdevs
1 month ago
176
3
General

Which is better, Spatie Permissions & Roles or using Middlewares or Policies?

Posted 1 month ago by reviewdevs

Hello, am trying to make something like Udemy as practice after finishing some courses here on Laracasts

I'm trying to fix a problem where I want to allow users who purchased a course to view it, if not, they get 401

I was thinking of two approaches, either using Policies combined with Roles and permissions

like saying

if user can view any course, then respond to him with the courses videos

else, check if user has this course in his purchased courses, then send him the course videos

else, unauthorized

that was the the Policies + roles & permissions approach

but i read that u can do so with Middlewares and it seemed easier to do it with middlewares from this article

https://justlaravel.com/middleware-laravel-content-restriction-user-role/

so i was wondering if someone could explain to me which is better and more scalable in the future

thanks a lot!

Please sign in or create an account to participate in this conversation.