Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hamburghost's avatar

Imposing limits based on Cashier plans

Hi,

I was wondering if anyone has experience with imposing limits on features based on the user's current plan (using Cashier). For instance, let's say we have a netflix-like app that has 3 monthly plans:

  • monthly-1
  • monthly-2
  • monthly-unlimited

Restricting users to certain areas of the site or features seems trivial enough using subscribed(). For example if only users on the monthly-2 or monthly-unlimited plans were allowed to watch in HD we could do something like (probably not the best way but just an example):

public function getHdLink(Video $video)
{
    if (Auth::user()->subscribed('monthly-1')) {
        throw new AccessDeniedException("You should upgrade your plan to watch in HD");
    }

    return "...";
}

But what if we wanted to restrict the number of videos people are allowed to watch depending on their plan? What I'm doing now is something like this:

// in a controller
public function watch(Video $video)
{
    $view_counts = Auth::user()->activities()->count();
    
    if (Auth::user()->subscribed('monthly-1') && $view_counts >= 25) {
        throw new Exception("You watched too many movies");
    }
}

Now this seems really messy and it's hard to test so I'm thinking there has to be a better way and would love to hear some suggestions.

Thanks!

0 likes
0 replies

Please or to participate in this conversation.