public function viewAs(Request $request) { $id = $request->input('user_id'); $user = User::find($id); $this->setCurrentUser($user); \Toastr::warning($user->username, 'Viewing as...'); return redirect()->back(); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (!Auth::user()->isAdmin()) { if ($request->ajax()) { return response('Unauthorized.', 401); } else { \Toastr::warning('Not authorised to view that page'); return redirect('/dashboard'); } } return $next($request); }
/** * ban or unban the user * * @param $id */ public function banORunBan($id) { $user = $this->findById($id); if ($user->banned === 0) { \Toastr::warning('User banned!', $title = $user->name, $options = []); $user->banned = true; } else { \Toastr::info('User unbanned!', $title = $user->name, $options = []); $user->banned = false; } $user->update(); }