Last active
September 10, 2016 13:12
-
-
Save nissicreative/8f6c00b5b35b2219a637211368c62a31 to your computer and use it in GitHub Desktop.
Laravel AdminController Stub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Controllers; | |
| use Exception; | |
| use Laracasts\Flash\Flash; | |
| use Illuminate\Http\Request; | |
| use Illuminate\Support\Facades\Auth; | |
| use Illuminate\Support\Facades\Hash; | |
| use Illuminate\Support\Facades\Redirect; | |
| class AdminController extends Controller | |
| { | |
| /* | |
| * Administrator Dashboard | |
| */ | |
| public function dashboard() | |
| { | |
| return view('admin.dashboard', compact('')); | |
| } | |
| /* | |
| * Show the form for editing authenticated user's account. | |
| */ | |
| public function getAccount() | |
| { | |
| $user = Auth::user(); | |
| return view('admin.account', compact('user')); | |
| } | |
| /* | |
| * Update authenticated user's account information. | |
| */ | |
| public function postAccount(Request $request) | |
| { | |
| $user = Auth::user(); | |
| $this->validate($request, [ | |
| 'first_name' => 'required', | |
| 'last_name' => 'required', | |
| 'email' => 'required|email|unique:users,email,' . $user->id, | |
| 'current_password' => 'required_with:new_password', | |
| 'new_password' => 'min:6' | |
| ]); | |
| $user->fill($request->only(['first_name', 'last_name', 'email'])); | |
| // Update password request | |
| if ($request->has('new_password')) { | |
| try { | |
| if ( ! Hash::check($request->current_password, $user->password)) { | |
| throw new Exception('Invalid password supplied.', 1); | |
| } | |
| } catch (Exception $e) { | |
| return Redirect::back()->withErrors(['current_password' => $e->getMessage()])->withInput(); | |
| } | |
| } | |
| $user->save(); | |
| Flash::success('Account Updated!'); | |
| return Redirect::route('admin.dashboard'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment