Unable to set cookie with Laravel Lumen

时光怂恿深爱的人放手 提交于 2019-12-11 12:57:38

问题


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

How to solve this problem ?


回答1:


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

or

use Illuminate\Http\Response;

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

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



来源:https://stackoverflow.com/questions/30545555/unable-to-set-cookie-with-laravel-lumen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!