无法使用Laravel Lumen设置cookie [英] Unable to set cookie with Laravel Lumen

查看:441
本文介绍了无法使用Laravel Lumen设置cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档,我试图创建一个简单的cookie,但这不起作用.

According to the documentation, I am trying to create a simple cookie, but this don't work.

我使用以下代码创建它:

I create it by using the following code :

$response = new Illuminate\Http\Response('Hello World');
$response->withCookie(cookie('name', 'value', 43920)); // 43920 = 1 month

当我试图在视图中查看它时,出现以下错误消息:

When I'm trying to see it in the view, I get this error message :

 Fatal error: Class 'App\Http\Controllers\Illuminate\Http\Response' not found in [...]\app\Http\Controllers\nameController.php

如何解决这个问题?

推荐答案

$response = new \Illuminate\Http\Response('Hello World');

use Illuminate\Http\Response;

$response = new Response('Hello World');

详细了解名称空间的基本用法: http://php.net/manual /en/language.namespaces.basics.php

Read more about namespaces basic usage: http://php.net/manual/en/language.namespaces.basics.php

这篇关于无法使用Laravel Lumen设置cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆