Exemplo n.º 1
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $user = User::find($id);
     if ($user->profile_id) {
         $profile = Profile::find($user->profile_id);
     } else {
         $profile = new Profile();
         $profile->name = $user->name;
         $profile->pic = 'avatar3.png';
         $profile->save();
         $user->profile_id = $profile->_id;
         $user->save();
     }
     return view('user.show')->with(['user' => $user, 'profile' => $profile]);
 }
Exemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(StoreProfileRequest $request)
 {
     $profile_pic = 'avatar3.png';
     if (\Input::file('image')->isValid()) {
         $destinationPath = public_path('img/');
         // upload path
         $extension = \Input::file('image')->getClientOriginalExtension();
         // getting image extension
         $fileName = rand(11111, 99999) . '.' . $extension;
         // renameing image
         \Input::file('image')->move($destinationPath, $fileName);
         // uploading file to given path
         $profile_pic = $fileName;
     }
     $profile = new Profile();
     $profile->name = $request->name;
     $profile->pic = $profile_pic;
     $profile->save();
     $user = \Auth::user();
     $user->profile_id = $profile->_id;
     $user->save();
     return redirect('profile');
 }