SHARE
TWEET

Untitled

a guest Jul 20th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use App\User;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Auth;
  8.  
  9. class UserController extends Controller
  10. {
  11.     public function showProfile($user_id){
  12.         $user = User::find($user_id);
  13.         if(!$user){
  14.             return abort('404');
  15.         }
  16.         return view('users.profile')->with(['profile' => $user->profile]);
  17.     }
  18.  
  19.     public function editAccount(){
  20.         return view('users.account');
  21.     }
  22.  
  23.     public function editAccountHandler(Request $request){
  24.         $data = $request->validate([
  25.             'name' => ['required', 'string', 'max:255'],
  26.             'description' => ['nullable', 'string', 'max:65535']
  27.         ]);
  28.         $user = Auth::user();
  29.         if(!$user){
  30.             return redirect()->back()->with('error', __('errors.something_wrong_try_again'));
  31.         }
  32.         $user->name = $data['name'];
  33.         $user->profile->description = $data['description'];
  34.         $user->profile->save();
  35.         $user->save();
  36.         return redirect()->route('account')->with('success', __('errors.account_successfully_edited'));
  37.     }
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top