laravel使用witherror返回错误

        if(!session('name')){
                return redirect('book')->withErrors('请登录');
        }    

首先在后台使用withErrors放回错误信息

前台页面通过全局函数$errors接收错误信息,通过循环在页面展示

    @foreach($errors->all() as $error)
    <h3>{{ $error }}</h3>
    @endforeach
posted @ 2020-01-13 19:13  Duanson  阅读(1283)  评论(0编辑  收藏  举报