终止 laravel 不在路由处理程序中的应用程序并发送响应

Terminate laravel app not in route handler and send response

我需要在 class 方法中终止 laravel 应用程序,而不是在路由处理程序中。 我使用自定义异常和方法 render() 它工作正常但我认为这不是最好的方法。

我使用的第二种方式:

redirect()->back()->with(...)->send();
die();

但是通过这种方式不能使用 with() 方法和会话刷新,只能重定向... 当我转储会话时它是空的...... 解决此问题的最佳方法是什么?

当你使用die()函数时,你停止执行并且Laravel不会在会话中写入执行期间添加的数据,你需要使用session()->save()强制写入在会话中,但不这样做是更好的方法。

也许你可以在你的代码中加入一个returnreturn redirect()->back()->with(...)->send();