Auth过滤器在Laravel中不起作用

时间:2014-10-03 17:43:04

标签: php laravel

我在Laravel中构建一个API来学习如何做这样的事情。我遵循Laracasts课程来做这件事,但我无法让$this->beforeFilter('auth.basic');工作。这是我的控制者:

class LessonsController extends ApiController {

    protected $lessonstranformer;   

    function __construct(LessonTransformer $lessonTransformer)
    {

        $this->LessonTransformer = $lessonTransformer;

        $this->beforeFilter('auth.basic');

    }

    public function index() 
    {

        $lessons = Lessons::all();

        return $this->respond([

            'data' => $this->LessonTransformer->transformCollection($lessons->all())

        ]);

    }

}

1 个答案:

答案 0 :(得分:0)

可能有一件事可能导致问题,那就是:

$this->LessonTransformer = $lessonTransformer;

应该是:

$this->lessonTransformer = $lessonTransformer;

因为protected $lessonstranformer不是protected $Lessonstranformer。另外,请确保ApiController扩展ControllerBaseController,这可能会扩展Controller