How to make Laravel return a View's “Content-Type” header as “application/javascript”?

前端 未结 6 1314
-上瘾入骨i
-上瘾入骨i 2020-12-14 08:41

I\'m trying to output a dynamic javascript file for inclusion from external websites with the [script src=\"\"] tag. As the view is using the Blade engine, it\'

6条回答
  •  星月不相逢
    2020-12-14 09:19

    Laravel lets you modify header information via the Response class, so you have to make use of it. Remove the header line from your view and try it like this in your controller:

    $contents = View::make('embedded')->with('foo', $foo);
    $response = Response::make($contents, $statusCode);
    $response->header('Content-Type', 'application/javascript');
    return $response;
    

提交回复
热议问题