Browse Source

Move user profile to own controller

pull/1/head
Nafies Luthfi 8 years ago
parent
commit
aac92385da
  1. 37
      app/Http/Controllers/Auth/ProfileController.php
  2. 23
      app/Http/Controllers/AuthController.php
  3. 7
      routes/web/account.php

37
app/Http/Controllers/Auth/ProfileController.php

@ -0,0 +1,37 @@
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class ProfileController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function show()
{
return view('auth.profile', ['user' => auth()->user()]);
}
public function update(Request $request)
{
$profileData = $request->validate([
'name' => 'required|max:60',
'email' => 'required|email',
]);
$user = auth()->user();
$user->name = $profileData['name'];
$user->email = $profileData['email'];
$user->save();
flash()->success(trans('auth.profile_updated'));
return back();
}
}

23
app/Http/Controllers/AuthController.php

@ -70,27 +70,4 @@ class AuthController extends Controller
flash()->success(trans('auth.welcome', ['name' => $user->name])); flash()->success(trans('auth.welcome', ['name' => $user->name]));
return redirect()->route('home'); return redirect()->route('home');
} }
public function getProfile()
{
$user = Auth::user();
return view('auth.profile', compact('user'));
}
public function patchProfile(Request $request)
{
$profileData = $request->validate([
'name' => 'required|max:60',
'email' => 'required|email',
]);
$user = auth()->user();
$user->name = $profileData['name'];
$user->email = $profileData['email'];
$user->save();
flash()->success(trans('auth.profile_updated'));
return back();
}
} }

7
routes/web/account.php

@ -8,11 +8,12 @@ Route::group(['middleware' => 'web','as'=>'auth.'], function() {
Route::get('logout', ['as'=>'logout', 'uses' => 'AuthController@getLogout']); Route::get('logout', ['as'=>'logout', 'uses' => 'AuthController@getLogout']);
Route::get('register', ['as'=>'register', 'uses' => 'AuthController@getRegister']); Route::get('register', ['as'=>'register', 'uses' => 'AuthController@getRegister']);
Route::post('register', ['as'=>'register', 'uses' => 'AuthController@postRegister']); Route::post('register', ['as'=>'register', 'uses' => 'AuthController@postRegister']);
Route::get('activate', ['as'=>'activate', 'uses' => 'AuthController@getActivate']);
Route::get('profile', ['as'=>'profile', 'uses' => 'AuthController@getProfile']);
Route::patch('profile', ['as'=>'profile', 'uses' => 'AuthController@patchProfile']);
}); });
// User Profile Routes...
Route::get('profile', ['uses' => 'Auth\ProfileController@show'])->name('auth.profile');
Route::patch('profile', ['uses' => 'Auth\ProfileController@update'])->name('auth.profile');
// Change Password Routes... // Change Password Routes...
Route::get('change-password', 'Auth\ChangePasswordController@show')->name('auth.change-password'); Route::get('change-password', 'Auth\ChangePasswordController@show')->name('auth.change-password');
Route::patch('change-password', 'Auth\ChangePasswordController@update')->name('auth.change-password'); Route::patch('change-password', 'Auth\ChangePasswordController@update')->name('auth.change-password');

Loading…
Cancel
Save