问题
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