Skip to content
全部文档

HTTP 响应

创建响应

字符串与数组

所有路由和控制器都应返回一个响应,以便发回用户的浏览器。Laravel 提供了多种返回响应的方式。最基本的响应是从路由或控制器返回字符串。框架会自动将该字符串转换为完整的 HTTP 响应:

php
Route::get('/', function () {
    return 'Hello World';
});

除了从路由和控制器返回字符串外,你也可以返回数组。框架会自动将该数组转换为 JSON 响应:

php
Route::get('/', function () {
    return [1, 2, 3];
});

INFO

你知道也可以从路由或控制器返回 Eloquent 集合 吗?它们会自动转换为 JSON。试试看!

响应对象

通常,你不会只从路由动作返回简单的字符串或数组,而是返回完整的 Illuminate\Http\Response 实例或 视图

返回完整的 Response 实例可让你自定义响应的 HTTP 状态码和头。Response 实例继承自 Symfony\Component\HttpFoundation\Response 类,该类提供了多种构建 HTTP 响应的方法:

php
Route::get('/home', function () {
    return response('Hello World', 200)
        ->header('Content-Type', 'text/plain');
});

Eloquent 模型与集合

你也可以直接从路由和控制器返回 Eloquent ORM 模型和集合。此时,Laravel 会在尊重模型的 隐藏属性 的同时,自动将模型和集合转换为 JSON 响应:

php
use App\Models\User;

Route::get('/user/{user}', function (User $user) {
    return $user;
});

向响应附加头

请记住,大多数响应方法都是可链式调用的,从而可以流畅地构建响应实例。例如,你可以在将响应发回用户之前,使用 header 方法向响应添加一系列头:

php
return response($content)
    ->header('Content-Type', $type)
    ->header('X-Header-One', 'Header Value')
    ->header('X-Header-Two', 'Header Value');

或者,你可以使用 withHeaders 方法指定要添加到响应的头数组:

php
return response($content)
    ->withHeaders([
        'Content-Type' => $type,
        'X-Header-One' => 'Header Value',
        'X-Header-Two' => 'Header Value',
    ]);

你可以使用 withoutHeader 方法从即将发出的响应中移除特定头:

php
return response($content)->withoutHeader('X-Debug');

return response($content)->withoutHeader(['X-Debug', 'X-Powered-By']);

缓存控制中间件

Laravel 包含 cache.headers 中间件,可用于为一组路由快速设置 Cache-Control 头。指令应使用对应 cache-control 指令的「snake case」形式,并用分号分隔。若指令列表中指定了 etag,响应内容的 MD5 哈希会自动设置为 ETag 标识符:

php
Route::middleware('cache.headers:public;max_age=30;s_maxage=300;stale_while_revalidate=600;etag')->group(function () {
    Route::get('/privacy', function () {
        // ...
    });

    Route::get('/terms', function () {
        // ...
    });
});

向响应附加 Cookie

你可以使用 cookie 方法向即将发出的 Illuminate\Http\Response 实例附加 Cookie。应向该方法传入名称、值以及 Cookie 应视为有效的分钟数:

php
return response('Hello World')->cookie(
    'name', 'value', $minutes
);

cookie 方法还接受一些较少使用的额外参数。一般而言,这些参数的用途和含义与 PHP 原生 setcookie 方法的参数相同:

php
return response('Hello World')->cookie(
    'name', 'value', $minutes, $path, $domain, $secure, $httpOnly
);

若你希望确保 Cookie 随即将发出的响应一起发送,但尚未拥有该响应的实例,可以使用 Cookie Facade「排队」Cookie,以便在发送时附加到响应。queue 方法接受创建 Cookie 实例所需的参数。这些 Cookie 会在响应发送到浏览器之前附加到即将发出的响应上:

php
use Illuminate\Support\Facades\Cookie;

Cookie::queue('name', 'value', $minutes);

若希望生成可稍后附加到响应实例的 Symfony\Component\HttpFoundation\Cookie 实例,可以使用全局 cookie 辅助函数。除非将该 Cookie 附加到响应实例,否则它不会发回客户端:

php
$cookie = cookie('name', 'value', $minutes);

return response('Hello World')->cookie($cookie);

提前使 Cookie 过期

你可以通过即将发出响应上的 withoutCookiewithoutCookies 方法使 Cookie 过期来移除它:

php
return response('Hello World')->withoutCookie('name');

return response('Hello World')->withoutCookies([
    'name',
    'email',
    'preferences',
]);

若尚未拥有即将发出响应的实例,可以使用 Cookie Facade 的 expire 方法使 Cookie 过期:

php
Cookie::expire('name');

Cookie 与加密

默认情况下,得益于 Illuminate\Cookie\Middleware\EncryptCookies 中间件,Laravel 生成的所有 Cookie 都经过加密和签名,从而无法被客户端修改或读取。若希望对应用生成的部分 Cookie 禁用加密,可以在应用的 bootstrap/app.php 文件中使用 encryptCookies 方法:

php
->withMiddleware(function (Middleware $middleware): void {
    $middleware->encryptCookies(except: [
        'cookie_name',
    ]);
})

INFO

一般而言,切勿禁用 Cookie 加密,因为这会使 Cookie 面临客户端数据暴露和篡改的风险。

重定向

重定向响应是 Illuminate\Http\RedirectResponse 类的实例,并包含将用户重定向到另一个 URL 所需的适当头。有多种方式生成 RedirectResponse 实例。最简单的方法是使用全局 redirect 辅助函数:

php
Route::get('/dashboard', function () {
    return redirect('/home/dashboard');
});

有时你可能希望将用户重定向到其先前位置,例如当提交的表单无效时。你可以使用全局 back 辅助函数实现。由于该功能使用 会话,请确保调用 back 函数的路由使用 web 中间件组:

php
Route::post('/user/profile', function () {
    // Validate the request...

    return back()->withInput();
});

重定向到命名路由

不带参数调用 redirect 辅助函数时,会返回 Illuminate\Routing\Redirector 实例,使你可以在该 Redirector 实例上调用任何方法。例如,要生成指向命名路由的 RedirectResponse,可以使用 route 方法:

php
return redirect()->route('login');

若路由有参数,可以将它们作为第二个参数传给 route 方法:

php
// For a route with the following URI: /profile/{id}

return redirect()->route('profile', ['id' => 1]);

通过 Eloquent 模型填充参数

若你重定向到带有从 Eloquent 模型填充的「ID」参数的路由,可以直接传入该模型。ID 会自动提取:

php
// For a route with the following URI: /profile/{id}

return redirect()->route('profile', [$user]);

若希望自定义放入路由参数的值,可以在路由参数定义中指定列(/profile/{id:slug}),或覆盖 Eloquent 模型上的 getRouteKey 方法:

php
/**
 * Get the value of the model's route key.
 */
public function getRouteKey(): mixed
{
    return $this->slug;
}

重定向到控制器动作

你也可以生成到 控制器动作 的重定向。为此,将控制器和动作名传给 action 方法:

php
use App\Http\Controllers\UserController;

return redirect()->action([UserController::class, 'index']);

若控制器路由需要参数,可以将它们作为第二个参数传给 action 方法:

php
return redirect()->action(
    [UserController::class, 'profile'], ['id' => 1]
);

重定向到外部域名

有时你可能需要重定向到应用之外的域名。你可以调用 away 方法实现,该方法会创建不进行额外 URL 编码、验证或校验的 RedirectResponse

php
return redirect()->away('https://www.google.com');

重定向并闪存会话数据

重定向到新 URL 与 向会话闪存数据 通常同时进行。这通常在成功执行某操作后,向会话闪存成功消息时完成。为方便起见,你可以在单个流畅的方法链中创建 RedirectResponse 实例并向会话闪存数据:

php
Route::post('/user/profile', function () {
    // ...

    return redirect('/dashboard')->with('status', 'Profile updated!');
});

用户被重定向后,你可以从 会话 显示闪存消息。例如,使用 Blade 语法

blade
@if (session('status'))
    <div class="alert alert-success">
        {{ session('status') }}
    </div>
@endif

重定向并携带输入

你可以使用 RedirectResponse 实例提供的 withInput 方法,在将用户重定向到新位置之前,将当前请求的输入数据闪存到会话。这通常在用户遇到验证错误时完成。输入闪存到会话后,你可以在下一次请求期间轻松 检索它 以重新填充表单:

php
return back()->withInput();

其他响应类型

response 辅助函数可用于生成其他类型的响应实例。不带参数调用 response 辅助函数时,会返回 Illuminate\Contracts\Routing\ResponseFactory 契约 的实现。该契约提供了多种用于生成响应的实用方法。

视图响应

若既需要控制响应的状态和头,又需要返回 视图 作为响应内容,应使用 view 方法:

php
return response()
    ->view('hello', $data, 200)
    ->header('Content-Type', $type);

当然,若不需要传递自定义 HTTP 状态码或自定义头,可以使用全局 view 辅助函数。

JSON 响应

json 方法会自动将 Content-Type 头设置为 application/json,并使用 PHP 的 json_encode 函数将给定数组转换为 JSON:

php
return response()->json([
    'name' => 'Abigail',
    'state' => 'CA',
]);

若希望创建 JSONP 响应,可以将 json 方法与 withCallback 方法结合使用:

php
return response()
    ->json(['name' => 'Abigail', 'state' => 'CA'])
    ->withCallback($request->input('callback'));

文件下载

download 方法可用于生成强制用户浏览器下载给定路径文件的响应。download 方法接受文件名作为第二个参数,该参数决定下载文件的用户所见的文件名。最后,你可以将 HTTP 头数组作为第三个参数传入该方法:

php
return response()->download($pathToFile);

return response()->download($pathToFile, $name, $headers);

WARNING

负责管理文件下载的 Symfony HttpFoundation 要求被下载的文件具有 ASCII 文件名。

文件响应

file 方法可用于在用户浏览器中直接显示图像或 PDF 等文件,而不是发起下载。该方法的第一个参数为文件的绝对路径,第二个参数为头数组:

php
return response()->file($pathToFile);

return response()->file($pathToFile, $headers);

流式响应

通过在生成数据时将其流式传输到客户端,你可以显著降低内存占用并提升性能,尤其适合非常大的响应。流式响应允许客户端在服务器完成发送之前就开始处理数据:

php
Route::get('/stream', function () {
    return response()->stream(function (): void {
        foreach (['developer', 'admin'] as $string) {
            echo $string;
            ob_flush();
            flush();
            sleep(2); // Simulate delay between chunks...
        }
    }, 200, ['X-Accel-Buffering' => 'no']);
});

为方便起见,若你传给 stream 方法的闭包返回 Generator,Laravel 会在生成器返回的字符串之间自动刷新输出缓冲区,并禁用 Nginx 输出缓冲:

php
Route::post('/chat', function () {
    return response()->stream(function (): Generator {
        $stream = OpenAI::client()->chat()->createStreamed(...);

        foreach ($stream as $response) {
            yield $response->choices[0];
        }
    });
});

消费流式响应

可以使用 Laravel 的 stream npm 包消费流式响应,该包提供了与 Laravel 响应和事件流交互的便捷 API。首先,安装 @laravel/stream-react@laravel/stream-vue@laravel/stream-svelte 包:

shell
npm install @laravel/stream-react
shell
npm install @laravel/stream-vue
shell
npm install @laravel/stream-svelte

然后,可以使用 useStream 消费事件流。提供流 URL 后,随着 Laravel 应用返回内容,该 hook 会自动用拼接后的响应更新 data

tsx
import { useStream } from "@laravel/stream-react";

function App() {
    const { data, isFetching, isStreaming, send } = useStream("chat");

    const sendMessage = () => {
        send({
            message: `Current timestamp: ${Date.now()}`,
        });
    };

    return (
        <div>
            <div>{data}</div>
            {isFetching && <div>Connecting...</div>}
            {isStreaming && <div>Generating...</div>}
            <button onClick={sendMessage}>Send Message</button>
        </div>
    );
}
vue
<script setup lang="ts">
import { useStream } from "@laravel/stream-vue";

const { data, isFetching, isStreaming, send } = useStream("chat");

const sendMessage = () => {
    send({
        message: `Current timestamp: ${Date.now()}`,
    });
};
</script>

<template>
    <div>
        <div>{{ data }}</div>
        <div v-if="isFetching">Connecting...</div>
        <div v-if="isStreaming">Generating...</div>
        <button @click="sendMessage">Send Message</button>
    </div>
</template>
svelte
<script>
import { useStream } from "@laravel/stream-svelte";

const stream = useStream("chat");

const sendMessage = () => {
    stream.send({
        message: `Current timestamp: ${Date.now()}`,
    });
};
</script>

<div>
    <div>{$stream.data}</div>
    {#if $stream.isFetching}
        <div>Connecting...</div>
    {/if}
    {#if $stream.isStreaming}
        <div>Generating...</div>
    {/if}
    <button onclick={sendMessage}>Send Message</button>
</div>

通过 send 向流发送数据时,会在发送新数据之前取消到该流的活动连接。所有请求都以 JSON POST 请求发送。

WARNING

由于 useStream hook 会向应用发起 POST 请求,因此需要有效的 CSRF 令牌。提供 CSRF 令牌最简单的方式是 通过应用布局 head 中的 meta 标签包含它

传给 useStream 的第二个参数是一个选项对象,可用于自定义流消费行为。该对象的默认值如下所示:

tsx
import { useStream } from "@laravel/stream-react";

function App() {
    const { data } = useStream("chat", {
        id: undefined,
        initialInput: undefined,
        headers: undefined,
        csrfToken: undefined,
        onResponse: (response: Response) => void,
        onData: (data: string) => void,
        onCancel: () => void,
        onFinish: () => void,
        onError: (error: Error) => void,
    });

    return <div>{data}</div>;
}
vue
<script setup lang="ts">
import { useStream } from "@laravel/stream-vue";

const { data } = useStream("chat", {
    id: undefined,
    initialInput: undefined,
    headers: undefined,
    csrfToken: undefined,
    onResponse: (response: Response) => void,
    onData: (data: string) => void,
    onCancel: () => void,
    onFinish: () => void,
    onError: (error: Error) => void,
});
</script>

<template>
    <div>{{ data }}</div>
</template>
svelte
<script>
import { useStream } from "@laravel/stream-svelte";

const stream = useStream("chat", {
    id: undefined,
    initialInput: undefined,
    headers: undefined,
    csrfToken: undefined,
    onResponse: (response) => {},
    onData: (data) => {},
    onCancel: () => {},
    onFinish: () => {},
    onError: (error) => {},
});
</script>

<div>{$stream.data}</div>

onResponse is triggered after a successful initial response from the stream and the raw Response is passed to the callback. onData is called as each chunk is received - the current chunk is passed to the callback. onFinish is called when a stream has finished and when an error is thrown during the fetch / read cycle.

默认情况下,初始化时不会向流发起请求。你可以使用 initialInput 选项向流传递初始负载:

tsx
import { useStream } from "@laravel/stream-react";

function App() {
    const { data } = useStream("chat", {
        initialInput: {
            message: "Introduce yourself.",
        },
    });

    return <div>{data}</div>;
}
vue
<script setup lang="ts">
import { useStream } from "@laravel/stream-vue";

const { data } = useStream("chat", {
    initialInput: {
        message: "Introduce yourself.",
    },
});
</script>

<template>
    <div>{{ data }}</div>
</template>
svelte
<script>
import { useStream } from "@laravel/stream-svelte";

const stream = useStream("chat", {
    initialInput: {
        message: "Introduce yourself.",
    },
});
</script>

<div>{$stream.data}</div>

要手动取消流,可以使用 hook 返回的 cancel 方法:

tsx
import { useStream } from "@laravel/stream-react";

function App() {
    const { data, cancel } = useStream("chat");

    return (
        <div>
            <div>{data}</div>
            <button onClick={cancel}>Cancel</button>
        </div>
    );
}
vue
<script setup lang="ts">
import { useStream } from "@laravel/stream-vue";

const { data, cancel } = useStream("chat");
</script>

<template>
    <div>
        <div>{{ data }}</div>
        <button @click="cancel">Cancel</button>
    </div>
</template>
svelte
<script>
import { useStream } from "@laravel/stream-svelte";

const stream = useStream("chat");
</script>

<div>
    <div>{$stream.data}</div>
    <button onclick={() => stream.cancel()}>Cancel</button>
</div>

每次使用 useStream hook 时,都会生成一个随机 id 来标识该流。它会在每次请求的 X-STREAM-ID 头中发回服务器。从多个组件消费同一流时,可以通过提供自己的 id 来读写该流:

tsx
// App.tsx
import { useStream } from "@laravel/stream-react";

function App() {
    const { data, id } = useStream("chat");

    return (
        <div>
            <div>{data}</div>
            <StreamStatus id={id} />
        </div>
    );
}

// StreamStatus.tsx
import { useStream } from "@laravel/stream-react";

function StreamStatus({ id }) {
    const { isFetching, isStreaming } = useStream("chat", { id });

    return (
        <div>
            {isFetching && <div>Connecting...</div>}
            {isStreaming && <div>Generating...</div>}
        </div>
    );
}
vue
<!-- App.vue -->
<script setup lang="ts">
import { useStream } from "@laravel/stream-vue";
import StreamStatus from "./StreamStatus.vue";

const { data, id } = useStream("chat");
</script>

<template>
    <div>
        <div>{{ data }}</div>
        <StreamStatus :id="id" />
    </div>
</template>

<!-- StreamStatus.vue -->
<script setup lang="ts">
import { useStream } from "@laravel/stream-vue";

const props = defineProps<{
    id: string;
}>();

const { isFetching, isStreaming } = useStream("chat", { id: props.id });
</script>

<template>
    <div>
        <div v-if="isFetching">Connecting...</div>
        <div v-if="isStreaming">Generating...</div>
    </div>
</template>
svelte
<!-- App.svelte -->
<script>
import { useStream } from "@laravel/stream-svelte";
import StreamStatus from "./StreamStatus.svelte";

const stream = useStream("chat");
</script>

<div>
    <div>{$stream.data}</div>
    <StreamStatus id={stream.id} />
</div>

<!-- StreamStatus.svelte -->
<script>
import { useStream } from "@laravel/stream-svelte";

let { id } = $props();

const stream = useStream("chat", { id });
</script>

<div>
    {#if $stream.isFetching}
        <div>Connecting...</div>
    {/if}
    {#if $stream.isStreaming}
        <div>Generating...</div>
    {/if}
</div>

流式 JSON 响应

若需要增量流式传输 JSON 数据,可以使用 streamJson 方法。该方法特别适用于需要以易于 JavaScript 解析的格式逐步发送到浏览器的大型数据集:

php
use App\Models\User;

Route::get('/users.json', function () {
    return response()->streamJson([
        'users' => User::cursor(),
    ]);
});

useJsonStream hook 与 useStream hook 相同,不同之处在于流式传输完成后它会尝试将数据解析为 JSON:

tsx
import { useJsonStream } from "@laravel/stream-react";

type User = {
    id: number;
    name: string;
    email: string;
};

function App() {
    const { data, send } = useJsonStream<{ users: User[] }>("users");

    const loadUsers = () => {
        send({
            query: "taylor",
        });
    };

    return (
        <div>
            <ul>
                {data?.users.map((user) => (
                    <li>
                        {user.id}: {user.name}
                    </li>
                ))}
            </ul>
            <button onClick={loadUsers}>Load Users</button>
        </div>
    );
}
vue
<script setup lang="ts">
import { useJsonStream } from "@laravel/stream-vue";

type User = {
    id: number;
    name: string;
    email: string;
};

const { data, send } = useJsonStream<{ users: User[] }>("users");

const loadUsers = () => {
    send({
        query: "taylor",
    });
};
</script>

<template>
    <div>
        <ul>
            <li v-for="user in data?.users" :key="user.id">
                {{ user.id }}: {{ user.name }}
            </li>
        </ul>
        <button @click="loadUsers">Load Users</button>
    </div>
</template>
svelte
<script>
import { useJsonStream } from "@laravel/stream-svelte";

const stream = useJsonStream("users");

const loadUsers = () => {
    stream.send({
        query: "taylor",
    });
};
</script>

<div>
    <ul>
        {#if $stream.data?.users}
            {#each $stream.data.users as user (user.id)}
                <li>{user.id}: {user.name}</li>
            {/each}
        {/if}
    </ul>
    <button onclick={loadUsers}>Load Users</button>
</div>

事件流(SSE)

eventStream 方法可用于返回使用 text/event-stream 内容类型的服务器发送事件(SSE)流式响应。eventStream 方法接受一个闭包,该闭包应在响应可用时向流 yield 响应:

php
Route::get('/chat', function () {
    return response()->eventStream(function () {
        $stream = OpenAI::client()->chat()->createStreamed(...);

        foreach ($stream as $response) {
            yield $response->choices[0];
        }
    });
});

若希望自定义事件名称,可以 yield StreamedEvent 类的实例:

php
use Illuminate\Http\StreamedEvent;

yield new StreamedEvent(
    event: 'update',
    data: $response->choices[0],
);

消费事件流

可以使用 Laravel 的 stream npm 包消费事件流,该包提供了与 Laravel 事件流交互的便捷 API。首先,安装 @laravel/stream-react@laravel/stream-vue@laravel/stream-svelte 包:

shell
npm install @laravel/stream-react
shell
npm install @laravel/stream-vue
shell
npm install @laravel/stream-svelte

然后,可以使用 useEventStream 消费事件流。提供流 URL 后,随着 Laravel 应用返回消息,该 hook 会自动用拼接后的响应更新 message

jsx
import { useEventStream } from "@laravel/stream-react";

function App() {
  const { message } = useEventStream("/chat");

  return <div>{message}</div>;
}
vue
<script setup lang="ts">
import { useEventStream } from "@laravel/stream-vue";

const { message } = useEventStream("/chat");
</script>

<template>
  <div>{{ message }}</div>
</template>
svelte
<script>
import { useEventStream } from "@laravel/stream-svelte";

const eventStream = useEventStream("/chat");
</script>

<div>{$eventStream.message}</div>

传给 useEventStream 的第二个参数是一个选项对象,可用于自定义流消费行为。该对象的默认值如下所示:

jsx
import { useEventStream } from "@laravel/stream-react";

function App() {
  const { message } = useEventStream("/stream", {
    eventName: "update",
    onMessage: (message) => {
      //
    },
    onError: (error) => {
      //
    },
    onComplete: () => {
      //
    },
    endSignal: "</stream>",
    glue: " ",
  });

  return <div>{message}</div>;
}
vue
<script setup lang="ts">
import { useEventStream } from "@laravel/stream-vue";

const { message } = useEventStream("/chat", {
  eventName: "update",
  onMessage: (message) => {
    // ...
  },
  onError: (error) => {
    // ...
  },
  onComplete: () => {
    // ...
  },
  endSignal: "</stream>",
  glue: " ",
});
</script>
svelte
<script>
import { useEventStream } from "@laravel/stream-svelte";

const eventStream = useEventStream("/chat", {
    eventName: "update",
    onMessage: (event) => {
        //
    },
    onError: (error) => {
        //
    },
    onComplete: () => {
        //
    },
    endSignal: "</stream>",
    glue: " ",
    replace: false,
});
</script>

事件流也可以由应用前端通过 EventSource 对象手动消费。流完成时,eventStream 方法会自动向事件流发送 </stream> 更新:

js
const source = new EventSource('/chat');

source.addEventListener('update', (event) => {
    if (event.data === '</stream>') {
        source.close();

        return;
    }

    console.log(event.data);
});

要自定义发送到事件流的最终事件,可以向 eventStream 方法的 endStreamWith 参数提供一个 StreamedEvent 实例:

php
return response()->eventStream(function () {
    // ...
}, endStreamWith: new StreamedEvent(event: 'update', data: '</stream>'));

流式下载

有时你可能希望将某次操作的字符串响应转为可下载响应,而无需将操作内容写入磁盘。在这种场景下可以使用 streamDownload 方法。该方法接受回调、文件名以及可选的头数组作为参数:

php
use App\Services\GitHub;

return response()->streamDownload(function () {
    echo GitHub::api('repo')
        ->contents()
        ->readme('laravel', 'laravel')['contents'];
}, 'laravel-readme.md');

响应宏

若希望定义可在多种路由和控制器中复用的自定义响应,可以在 Response Facade 上使用 macro 方法。通常应在应用的某个 服务提供者(例如 App\Providers\AppServiceProvider)的 boot 方法中调用该方法:

php
<?php

namespace App\Providers;

use Illuminate\Support\Facades\Response;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        Response::macro('caps', function (string $value) {
            return Response::make(strtoupper($value));
        });
    }
}

macro 函数的第一个参数是名称,第二个参数是闭包。从 ResponseFactory 实现或 response 辅助函数调用该宏名称时,会执行宏的闭包:

php
return response()->caps('foo');