douyuepi6485 2017-09-14 03: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.

  • 写回答

1条回答 默认 最新

  • doucong6884 2017-09-14 04: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);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部