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

sebastian.virlan's avatar

Check if subscription limitation is reached for an inseration

Hi, I have 15 CRUD pages. Every user has a subscription with some limitations on the number of elements from a CRUD page.

For example:

CRUD 1 can have maximum 200 records

CRUD 2 can have maximum 50 records

My store method for CRUD 1 looks like:

    public function store(AgentStoreRequest $request)
    {
        if (!Auth::user()->can('create-agent'))
            return response()->json(['response' => 'create_not_allowed'], 403);

        if(!$agent = User::create($request->get('agent')))
            return response()->json(['response' => 'error_create'], 400);

        $company_employees = Role::where('name','company_employees')->first();
        $agent->attachRole($company_employees);

        return response()->json(['id' => $agent->id], 200);
    }

How would be best practice to check if the number of rows inserted is not equal with the number from the subscription settings?

  • I can do this in controller like:
if(Auth::user()->subscription()->plan()->max_agents > Agents::where('company_id', $company_id)->count())
     return response()->json(['response' => 'max_exceeded'], 403);

or I think in the AgentStoreRequest class in authorisation.

What do you think?

0 likes
0 replies

Please or to participate in this conversation.