Laravel 5.1调用未定义的方法Illuminate \ Support \ Facades \ Request :: cookie()

时间:2016-07-19 05:01:54

标签: cookies laravel-5.1

我试图在Laravel 5.1中的控制器中加载cookie的值,但我收到此错误:

FatalErrorException in SurveyController.php line 21: Call to undefined method Illuminate\Support\Facades\Request::cookie()

这是我的代码:

<?php

namespace App\Http\Controllers;
use Response;
use Request;
use Illuminate\Routing\Controller;
use Cookie;
use Log;

class SurveyController extends Controller {

    /**
     * Index method. Decide to resume a survey or start a new one.
     */
    public function index(Request $request) {

        dd($request->cookie('survey_id'));
    }
}

the documents我可以看出,这似乎是加载cookie值的正确方法。我做错了什么?

2 个答案:

答案 0 :(得分:1)

所以而不是

use Request;

尝试

use Illuminate\Http\Request;

答案 1 :(得分:1)

而不是使用

use Request;

使用Illuminate \ Support \ Facades \ Request

使用

use Illuminate\Http\Request;