【问题标题】:Laravel: Set Auth config for PackageLaravel:为包设置身份验证配置
【发布时间】:2014-04-24 11:08:19
【问题描述】:

我正在创建自己的包,我只想使用与应用程序身份验证表不同的表为我的包添加身份验证。

我找不到仅为我的包覆盖应用程序auth.table 配置的方法。 搜索我找到了this solution,它可以即时更改配置。

在我的代码中:

class EasytranslateServiceProvider extends ServiceProvider {

    [...]

    /**
     * Bootstrap the application events.
     *
     * @return void
     */
    public function boot()
    {
        $this->package('revolistic/easytranslate');

        // add the packages routes
        include __DIR__.'/../../routes.php';

        // doesn't work 
        $this->app['config']['auth'] =  \Config::get('easytranslate::auth');
    }

    [...]
}

但是不起作用,看起来Auth模块在创建包或boot()函数调用之前正在读取配置。

如果我这样做:

class EasytranslateServiceProvider extends ServiceProvider {

    [...]

    /**
     * Bootstrap the application events.
     *
     * @return void
     */
    public function boot()
    {
        $this->package('revolistic/easytranslate');

        // add the packages routes
        include __DIR__.'/../../routes.php';

        // doesn't work 
        $this->app['config']['auth'] =  \Config::get('easytranslate::auth');

        // show that the changes was made
        print_r($this->app['config']['auth']);
    }

    [...]
}

我知道配置已更改,但 Auth 模型仍在使用应用程序身份验证配置文件中的表名。

我正在使用最新版本的 Laravel,知道如何完成它吗?

提前致谢

【问题讨论】:

    标签: authentication laravel laravel-4 package config


    【解决方案1】:

    哦,这个解决方案有效,我发现我的错误我应该像这样在我的包身份验证文件中命名我的模型

    'model' => 'Revolistic\Easytranslate\User',
    

    干杯

    【讨论】:

    猜你喜欢
    • 2016-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2016-03-12
    相关资源
    最近更新 更多