控制器 namespace App\Http\Controllers\Customer; use App\Http\Controllers\Controller; class Error extends Controller { public static function index(){ //验证参数 if(!empty(session('message')) && !empty(session('url')) && !empty(session('jumpTime'))){ $data = [ 'message' => session('message'), 'url' => session('url'), 'jumpTime' => session('jumpTime'), 'response' => session('response') ]; } else { $data = [ 'message' => '请勿非法访问!', 'url' => '/', 'jumpTime' => 3, 'response' => false ]; } return view('customer.error.error',['data' => $data]); } }
路由:
Route::resource('/error','Error');
使用:
redirect('/error')->with(['message'=>'登录成功,即将跳转到后台首页','url' =>'/home', 'jumpTime'=>3,'response'=>'302']);
blade页面:
@include('customer.public.css') <style> .layadmin-tips { margin-top: 30px; text-align: center; } .layadmin-tips .layui-icon[face] { display: inline-block; font-size: 300px; color: #393D49; } .layadmin-tips .layui-text { width: 500px; margin: 30px auto; padding-top: 20px; border-top: 5px solid #009688; font-size: 16px; } </style> <div class=""> <div class="layui-fluid"> <div class="layadmin-tips"> <i class="layui-icon" face></i> <div class="layui-text" style="font-size: 20px;"> {{$data['message']}} </div> </div> </div> </div> <div style="display: none"> <div id="response">{{$data['response']}}</div> <div id="url">{{$data['url']}}</div> </div> @include('customer.public.script') @include('customer.public.footer') <script> $(function () { var response = $("#response").html(); var url = $("#url").html(); if(response == '302'){ if(self != top){ setTimeout(top.location.href = url,5000); }else { setTimeout(window.location.href = url,5000); } } }) </script>