【问题标题】:Call to undefined method Illuminate\Routing\Route::header()调用未定义的方法 Illuminate\Routing\Route::header()
【发布时间】:2020-03-02 09:10:08
【问题描述】:

在 Laravel 4 中,我正在尝试将特定标头设置为我的路线。

我有

Route::filter('api', function($response){
    $response->header("Access-Control-Allow-Origin","*");
    if (Input::get('key') != 'bheng')
    {
        return Response::view('errors.404', array(), 404);
    }
});

我一直得到

调用未定义的方法 Illuminate\Routing\Route::header()

我正在尝试设置它,所以我不再收到 CORS 错误。

【问题讨论】:

标签: php laravel-4


【解决方案1】:

基于Laravel documentation

过滤器收到 $response 作为第三个参数传递给过滤器后

  Route::filter('log', function($route, $request, $response)

   {
        //
   })

【讨论】:

    猜你喜欢
    • 2023-03-23
    • 2017-06-11
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 2021-05-15
    • 2020-01-23
    • 1970-01-01
    • 2020-05-29
    相关资源
    最近更新 更多