简体   繁体   English

Laravel 5.2无法使身份验证中间件在资源控制器中工作

[英]Laravel 5.2 Cannot get auth middleware to work in resource controller

This is how the HolidaysController looks like at the moment: 这是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);
}

The auth middleware is the boilerplate Laravel middleware, I haven't changed it. auth中间件是样板的Laravel中间件,我没有更改。 Once I logout and then try to access the /holidays route, which leads to the index() method above, I get the following ErrorException, instead of it going to the login page as it should: 一旦我注销然后尝试访问/holidays路由(该路由导致上面的index()方法index() ,我将得到以下ErrorException,而不是按应有的方式进入登录页面:

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

I've refreshed Apache several times, but it still doesn't seem to work right. 我已经刷新过几次Apache,但是它似乎仍然无法正常工作。

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

_construct != __construct

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM