【问题标题】:Laravel Spark referToTeamAs method is not workingLaravel Spark referToTeamAs 方法不起作用
【发布时间】:2017-10-25 08:44:05
【问题描述】:

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

当我访问 /missing-group 时出现 404 错误,因为 /spark/src/Http/routes.php 中的 var_dumping $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();
}

...

【问题讨论】:

  • 你能发布你SparkServiceProvider.php的那部分吗?
  • @Samsquanch 我已经添加了 SparkServiceProvider 的相关部分
  • 来自文档 -- 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.
  • 成功了!提交它作为答案,我会给你答案!谢谢。

标签: laravel laravel-spark


【解决方案1】:

在 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 的提供者列表中,它就可以工作了!

【讨论】:

    【解决方案2】:

    来自the docs

    请务必在您的服务的注册方法中调用此方法 提供程序,因为如果在 引导方法。此外,请确保您通过单数, 单词的小写形式。

    所以不是

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

    你会想要的

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 2016-04-06
        • 1970-01-01
        • 2018-09-15
        • 2018-12-22
        • 2016-12-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多