Laravel-不应触发中间件吗? [英] Laravel - Middleware triggered while it should not?

查看:93
本文介绍了Laravel-不应触发中间件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel 5.4Vuejs 2.3以及VueRouter

我有一个由两部分组成的网站

I have a website that consists of two parts

  1. example.com
  2. example.com/tools

问题

如果我在example.com/tools,并且如果我reload the page到相同的地址example.com/tools,则触发中间件checkUsersPublic,而该中间件仅链接到/.

Problem

If I am at example.com/tools and if I reload the page to the same address example.com/tools the middleware checkUsersPublic is triggered whereas it is only linked to /.

如果我从VueRouter.js中删除{ path: '/tools', component: Stats },则不再触发中间件

If I remove { path: '/tools', component: Stats } from VueRouter.js the middleware is not triggered anymore

  • 我该怎么做才能不触发中间件?
Route::get('/', 'HomeController@home')->middleware('checkUserPublic')
Route::get('/tools', 'StatsController@home')->middleware('checkUserStats')

Vue路由器

const routes = [
    { path: '/', component: App },
    { path: '/tools', component: Stats },
];

中间件checkUsersPublic

class checkUsersPublic
{
    public function handle($request, Closure $next)
    {
        if(auth()->check() && auth()->user()->public_only) {
            return $next($request);
        }
        if(Auth::check()) {Auth::logout();}
        return $next($request);
    }
}

推荐答案

我不是在Laravel中使用中间件,而是在vue-router防护中在vue-router中完成了

Instead of doing the middleware in Laravel I did it within vue-router in the beforeEnter guard

这篇关于Laravel-不应触发中间件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆