dsgni26260 2017-12-05 08:50
浏览 81
已采纳

Laravel 5 Route :: when()替换

Is there a way to provide in Laravel 5.5 what 4.2 had with:

Route::when('*-ajax', 'ajax');

I had an option to attach a filter to all ajax routes, and since then I know that filters have been replaced with middleware, but I am getting an error that:

Attribute [when] does not exist.
  • 写回答

2条回答 默认 最新

  • douzhengnao8265 2017-12-21 09:23
    关注

    I found a solution in having implemented a global middleware for this:

    public function handle($request, Closure $next)
    {
        $parsedUrl = parse_url($request->url());
    
        if (key_exists('path', $parsedUrl) && strpos($parsedUrl['path'], '-ajax') !== false && !$request->ajax()) {
            return response('Bad request', 400);
        }
    
        return $next($request);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥15 C#字典调用时报错,有关文件加载
  • ¥100 在连接内网VPN时,如何同时保持互联网连接
  • ¥15 MATLAB中使用parfor,矩阵Removal的有效索引在parfor循环中受限制
  • ¥20 Win 10 LTSC 1809版本如何无损提升到20H1版本
  • ¥50 win10 LTSC 虚拟键盘不弹出
  • ¥30 关于PHP中POST获取数据的问题
  • ¥30 微信小程序请求失败,网页能正常带锁访问
  • ¥15 Python实现hog特征图可视化
  • ¥30 德飞莱51单片机实现C4炸弹