【发布时间】:2021-07-19 08:27:37
【问题描述】:
我正在使用 Laravel 7.0。
在我的 app/Exceptions/Handler.php 方法中“渲染”。我需要为“PostTooLargeException”创建条件。
请求是否来自 ajax 的响应是不同的。
问题是如果请求不是 ajax。我正在尝试返回一些错误消息,但是我想在函数“with()”或“withErrors()”中返回的任何内容在刀片视图中都不存在。
出了什么问题,为什么会这样?
我的代码:
if ($exception instanceof PostTooLargeException) {
if ($request->ajax()) {
return response(['message' => "The file you are trying to send is too large "], 422);
} {
$errors = new MessageBag();
$errors->add('error', 'test');
return Redirect::back()->withErrors($errors);
}
}
刀片:
@if($errors->any())
<div class="alert alert-danger">
<ul class="list-unstyled">
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
【问题讨论】:
标签: laravel