如何修复在Laravel 8中不起作用的闭包?

huangapple go评论49阅读模式
英文:

How to fix Closure ? not work in laravel 8

问题

无法为序列化准备路由[api/user]。使用了闭包。位于vendor/laravel/framework/src/Illuminate/Routing/Route.php:1150

英文:

Unable to prepare route [api/user] for serialization. Uses Closure. at vendor/laravel/framework/src/Illuminate/Routing/Route.php:1150

答案1

得分: 0

请运行 php artisan route:list 命令,并检查列表中是否存在任何闭包函数。

英文:

pls run php artisan route:list and check if there is any Closure in that list.

答案2

得分: 0

你无法缓存路由如果你使用了闭包。闭包是这部分:
public function (Request $request) { return $request->user(); }

相反,如果你将这段代码移到一个控制器中,你就能够缓存路由并消除错误。

英文:

You can't cache routes if you are using a closure. The closure is this part
public function (Request $request) {
return $request->user();
}

Instead, if you move the code into a controller you'll be able to cache the routes and eliminate the error.

huangapple
  • 本文由 发表于 2023年2月16日 14:34:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75468617.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定