drecy22400 2017-01-08 22:04 采纳率: 0%
浏览 133

Laravel 5.3控制器构造函数中的中间件回调函数

as mentioned in the documentation of Laravel 5.3 i am trying to add a middleware callback in the constructor of a controller

Controller's also allow you to register middleware using a Closure. This provides a convenient way to define a middleware for a single controller without defining an entire middleware class:

$this->middleware(function ($request, $next) {
    // ...
    return $next($request);
});

unfortunately i am getting the error:

Illegal offset type

which is logical because the middleware method of the Illuminate\Routing\Controller class accepts a the first param as an array only, i am not confused why would they add this code sample to the documentation although its not gonna work, or am I doing something wrong or missing something ?

documentation page

  • 写回答

1条回答 默认 最新

  • dououde4065 2017-01-08 22:55
    关注

    the laravel version should be at least:

    5.3.4

    评论

报告相同问题?

悬赏问题

  • ¥30 matlab解优化问题代码
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline