Laravel Spark referToTeamAs 方法无效

Laravel Spark referToTeamAs method is not working

在我的 SparkServiceProvider.php 中,您设置了 spark 配置和计划,我有 Spark::referToTeamAs('group');

当我访问 /missing-group 时出现 404 错误,因为 var_dumping /spark/src/Http/routes.php 中的 $teamString 显示 team 而不是 group。所以看起来我的设置在使用路由文件之前没有捕捉到。

有什么方法可以在调用路由文件之前设置 teamString 吗?比如更改服务提供商的顺序之类的?

我不太确定从哪里开始。提前致谢!

App\Providers\SparkServiceProvider

...

/**
 * Finish configuring Spark for the application.
 *
 * @return void
 */
public function booted()
{
    Spark::collectsBillingAddress();
    Spark::afterLoginRedirectTo('/dashboard');
    Spark::referToTeamAs('group');        

    Spark::useStripe()
        ->noProrate()
        ->noAdditionalTeams();

    Spark::plan('Individual', 'stripe-individual-ticket')
        ->price(300)
        ->features(['First', 'Second', 'Third'])
        ->yearly();

    Spark::teamPlan('Group', 'stripe-group-ticket')
        ->price(300)
        ->features(['First', 'Second', 'Third'])
        ->yearly();
}

...

在 Spark 定义路由之前添加另一个运行 boot() 方法的提供程序:

App\Providers\ConfigureSparkServiceProvider

<?php

namespace App\Providers;

use Laravel\Spark\Spark;
use Laravel\Spark\Providers\SparkServiceProvider as ServiceProvider;

class ConfigureSparkServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        Spark::referToTeamAs('group');

        parent::boot();
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

然后记得将它添加到 /config/app.php 中的提供者列表中,它就起作用了!

来自the docs

Be sure to call this method in the register method of your service provider, as Spark will not function correctly if it is called in the booted method. Additionally, make sure you pass the singular, lowercase form of the word.

所以不用

public function booted()
{
    ...
    Spark::referToTeamAs('group');
    ...

你会想要

public function register()
{
    ...
    Spark::referToTeamAs('group');
    ...

如果您使用的是 Spark 版本 6+ referToTeamAs 现在是 prefixTeamsAs