【问题标题】:Sentinel::check() always return FALSE in middlewareSentinel::check() 在中间件中总是返回 FALSE
【发布时间】:2018-01-01 19:46:52
【问题描述】:

这是我的路线:

Route::group(['middleware' => ['web']], function () {
    Route::get('/xx', 'xx\yy@zz');

这是我在 Kernel.php 中的修改:

protected $middlewareGroups = [
    'web' => [
    \Keevitaja\Linguist\LocalizeUrls::class,

LocalizeUrls.php:

public function handle($request, Closure $next)
    {
        if ($this->linguist->hasDefaultSlug() && $this->linguist->isDefaultDenied()) {
            abort(404);
        }

        if (Sentinel::check())
        {
            dd("logged in");
        }

        dd("NOT logged in");

我正在使用 Sentinel 和 Linguist 进行身份验证和本地化。 我想从用户模型中获取“system_language”:检查用户是否登录,如果他登录了,我想从数据库中获取他的首选语言,然后将其传递给语言学家:

$this->linguist->localize('fr');

不幸的是,Sentinel:check() 在这个中间件中总是返回 FALSE。在我自己的中间件中,它运行良好。

当然,我使用了正确的 Sentinel 外观,因为 $sentinel = Sentinel::findById(1); 返回一个有效结果。

【问题讨论】:

    标签: php laravel laravel-5 cartalyst-sentinel


    【解决方案1】:

    问题是由于 Kernel.php $middlewareGroups 中的顺序引起的,其中 \Keevitaja\Linguist\LocalizeUrls::class 位于首位。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-15
      • 2014-02-25
      • 2021-06-05
      • 2014-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-14
      相关资源
      最近更新 更多