/** * Responds to requests to GET /admin */ public function getAdmin() { // $user = \Auth::user(); // $role_id = $user->roles->pluck('id'); // // echo $user->roles; // // dump($user); // // echo $user->roles->pluck('id'); // // // if this does not get added to protected routes visting the page without // // logging in will throw error "unable to get property of non object" // if (! in_array(1, $role_id->toArray())){ // return "Access denied. You are not an administrator."; // } // return view('admin.admin'); // the code above has been replaced with a function from the User model // that returns 'TRUE' if the user has the admin role $userModel = new \App\User(); if ($userModel->isAdmin()) { return view('admin.admin'); } else { \Session::flash('flash_message', 'Access denied. Returning to previous page.'); //this will return to the previous URL return back(); } }