【发布时间】:2020-08-22 16:16:11
【问题描述】:
当请求是 json 时,我得到了我的 'xxx' 标头,但是当它是直接请求页面时 - 我的标头在响应中不存在。
我尝试了response()->header、response('content',200,['xxx'=>'xxx']) 的任何变体,但没有成功
我在控制器中的代码:
return $request->wantsJson()
? response([
'html' => view('components.tarif-list', compact('tarifs'))->render(),
'pagination' => $tarifs->appends(request()->query())->links()->toHtml(),
'head' => $seo_block,
'stats' => $stats
])->header('xxx','xxx')
: response(view('home',compact('tarifs','seo_block'))->render())->header('xxx','xxx');
home.blade.php
@extends('layouts.main')
@section('content')
<x-filters/>
<div id="head" class="alert alert-success" role="alert">
@if(!empty($seo_block))
{!! $seo_block !!}
@elseif($tarifs->isEmpty())
empty
@else
hello
@endif
</div>
{{$tarifs->appends(request()->query())->links()}}
<table id="tarif-list" class="table table-hover table-striped">
<x-tarif-list :tarifs="$tarifs"/>
</table>
{{$tarifs->appends(request()->query())->links()}}
@endsection
【问题讨论】:
-
我看不到任何代码,您正在检索响应标头?
-
为什么我需要检索它?我在 http 响应头中等待它
-
您需要以某种方式确保它是从控制器中检索到的,因此您需要将其转储到刀片文件中或在浏览器标头响应中查看。
-
嗯.. 我不知道如何将它转储到刀片中
-
\request()->headers->get('xxx')
标签: laravel http-headers response-headers