@php echo "userRepository = $userRepo; } /** * Display a listing of the User. * * @param Request $request */ public function index(Request $request) { $users = $this->userRepository->paginate(10); return view('users.index')->with('users', $users); } /** * Show the form for creating a new User. */ public function create() { return view('users.create'); } /** * Store a newly created User in storage. * * @param CreateUserRequest $request */ public function store(CreateUserRequest $request) { $input = $request->all(); $input['password'] = Hash::make($input['password']); $user = $this->userRepository->create($input); Flash::success('User saved successfully.'); return redirect(route('users.index')); } /** * Display the specified User. * * @param int $id */ public function show($id) { $user = $this->userRepository->find($id); if (empty($user)) { Flash::error('User not found'); return redirect(route('users.index')); } return view('users.show')->with('user', $user); } /** * Show the form for editing the specified User. * * @param int $id */ public function edit($id) { $user = $this->userRepository->find($id); if (empty($user)) { Flash::error('User not found'); return redirect(route('users.index')); } return view('users.edit')->with('user', $user); } /** * Update the specified User in storage. * * @param int $id * @param UpdateUserRequest $request */ public function update($id, UpdateUserRequest $request) { $user = $this->userRepository->find($id); if (empty($user)) { Flash::error('User not found'); return redirect(route('users.index')); } $input = $request->all(); if (!empty($input['password'])) { $input['password'] = Hash::make($input['password']); } else { unset($input['password']); } $user = $this->userRepository->update($input, $id); Flash::success('User updated successfully.'); return redirect(route('users.index')); } /** * Remove the specified User from storage. * * @param int $id * * @throws \Exception */ public function destroy($id) { $user = $this->userRepository->find($id); if (empty($user)) { Flash::error('User not found'); return redirect(route('users.index')); } $this->userRepository->delete($id); Flash::success('User deleted successfully.'); return redirect(route('users.index')); } }