Laravel 5.2无法让auth中间件在资源控制器中工作

时间:2016-09-18 21:29:05

标签: php laravel authentication

这就是HolidaysController目前的样子:

public function _construct(){

    $this->middleware('auth');
}
/**
 * Display a listing of the holidays.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
    // get all the holiday requests from the database
    $holidayReq = HolidayRequest::all();

    // load the view and pass the holiday requests
    return view('holidays.index')->with('holidayRequests',$holidayReq);
}

auth中间件是样板Laravel中间件,我没有改变它。 一旦我注销然后尝试访问/holidays路由,这导致上面的index()方法,我得到以下ErrorException,而不是它应该进入登录页面:

Trying to get property of non-object (View: *followed by long address of the blade file

我已经多次刷新Apache了,但它似乎仍然无法正常工作。

1 个答案:

答案 0 :(得分:2)

您定义为构造函数的方法不是PHP中的构造函数。

_construct != __construct