omrakhur
omrakhur

Reputation: 1402

Laravel 5.2 Cannot get auth middleware to work in resource controller

This is how the HolidaysController looks like at the moment:

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. 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:

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.

Upvotes: 0

Views: 67

Answers (1)

lagbox
lagbox

Reputation: 50481

Your method you defined as your constructor is not a constructor in PHP.

_construct != __construct

Upvotes: 2

Related Questions