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

nerginer's avatar

Laravel Spark Config

Hi,

Our organization has various departments, each with its own subscription plans. We maintain a shared user database, which includes a department field to identify the user's specific department. Our goal is to display the appropriate subscription plan to the user based on their department. How can we achieve this?

Regards,

Nuri

0 likes
5 replies
LaryAI's avatar
Level 58

One solution to achieve this would be to modify the Laravel Spark configuration to include department-specific subscription plans.

First, create a new configuration file for each department in the config/spark directory. For example, if you have departments named "Sales" and "Marketing", create two files named sales.php and marketing.php.

In each file, define the subscription plans specific to that department. For example, in sales.php, you could define the following plans:

return [
    'plans' => [
        'basic' => [
            'name' => 'Sales Basic',
            'price' => 10,
            'features' => [
                'Feature 1',
                'Feature 2',
                'Feature 3',
            ],
        ],
        'pro' => [
            'name' => 'Sales Pro',
            'price' => 20,
            'features' => [
                'Feature 1',
                'Feature 2',
                'Feature 3',
                'Feature 4',
                'Feature 5',
            ],
        ],
    ],
];

Repeat this process for each department, defining the appropriate subscription plans.

Next, modify the config/spark.php file to load the appropriate department configuration based on the user's department. You can do this by adding the following code to the boot method of your AppServiceProvider:

use Illuminate\Support\Facades\Config;

public function boot()
{
    Config::set('spark', require config('spark.department') ?? 'default');
}

This code sets the spark configuration to the appropriate department configuration based on the department value in your user database. If the department value is not set or does not match a configuration file, it falls back to the default configuration.

Finally, in your views, you can display the appropriate subscription plans using the spark-plans component and passing in the appropriate plan names. For example:

<spark-plans :plans="['basic', 'pro']"></spark-plans>

This will display the "Sales Basic" and "Sales Pro" plans if the user's department is "Sales".

Mercer14's avatar

Each inner array represents a different pricing plan, and contains several pieces of information about that plan:

'name': A string that provides a name or label for the plan 'price': A number that indicates the cost of the plan 'features': An array that lists the features included with the plan The 'basic' plan includes three features, while the 'pro' plan includes five features. The purpose of this code is likely to define the pricing plans so that they can be used elsewhere in the codebase, such as on a pricing page or in a checkout flow.

nerginer's avatar

@Mercer14 My question is spark specific. Can I show plans according to the user. Different users will see different plans according to their department

nerginer's avatar

I try : The config helper may also be used to set configuration variables at runtime by passing an array of key / value pairs: config(['app.debug' => true]);

For spark like

config(['spark.billables' => [

But not worked. Does spark loads the config file at start

Please or to participate in this conversation.