Laravel - Middleware triggered while it should not?

冷暖自知 提交于 2019-12-11 06:14:33

问题


I'm using Laravel 5.4 and Vuejs 2.3 along with VueRouter

I have a website that consists of two parts

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

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 /.

Edit

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

Question

  • What should I do change so the middleware is not triggered ?

Routes in Laravel

Route::get('/', 'HomeController@home')->middleware('checkUserPublic')
Route::get('/tools', 'StatsController@home')->middleware('checkUserStats')

Vue router

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

Middleware 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);
    }
}


回答1:


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



来源:https://stackoverflow.com/questions/43939648/laravel-middleware-triggered-while-it-should-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!