douyuepi6485
2017-09-14 11:40
浏览 38
已采纳

Laravel 5.5 - 强制用户对每个页面加载执行某些操作

In Laravel 5.5 is it possible to prevent already signed-in user from accessing any page other than one I specify?

Example: I would like to force user to select his/her Time zone under their profile before letting them access any other menu item. Hiding menu items until Time zone is selected is not an option. I've read about guards, middleware but cannot understand much of it.

Thank you.

图片转代码服务由CSDN问答提供 功能建议

在Laravel 5.5中,是否可以阻止已登录的用户访问我指定的页面以外的任何页面?

示例:我想强制用户在让他们访问任何其他菜单项之前,在他们的个人资料下选择他/她的时区。 隐藏菜单项直到选择时区不是一个选项。 我读过有关警卫,中间件但却无法理解的内容。

谢谢。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doucong6884 2017-09-14 12:11
    已采纳

    Use a middleware here middleware are the best choice to do task like this you can refer the doc for getting more about middleware

    <?php
    
    namespace App\Http\Middleware;
    
    use Closure;
    
    class AfterMiddleware
    {
        /**
         * Handle an incoming request.
         *
         * @param  \Illuminate\Http\Request  $request
         * @param  \Closure  $next
         * @return mixed
         */
        public function handle($request, Closure $next)
        {
            // your whatever logic
    
            return $next($request);
        }
    }
    
    点赞 打赏 评论

相关推荐 更多相似问题