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".