现在是 debug 模式,显示出详细问题是为了方便调试代码的,将 debug=false 就可以有友好提示了。
并且可以自定义配置错误模版,可以按照自己喜欢的样式展示了,如创建一个 errors/403.blade.php
,就可以通过自定义模版展示了。
在 view/errors/403.blade.php 创建文件
@extends('layouts.app')
@section('title', '403')
@section('content')
<div style="text-align: center ">
<h1>403 </h1>
<h2>{{$result}}</h2>
<a style='text-align: center' href="{{url()->previous()}}">返回上一页</a>
</div>
@endsection
【控制器】
public function edit(Topic $topic) { try { $this->authorize('update', $topic); }catch(AuthorizationException $e){ $result = '无权限'; return view('errors.403', compact('result')); } $categories = Category::all(); return view('topics.create_and_edit', compact('topic', 'categories')); }
推荐文章: