/**
  * @param UpdateUserProfileRequest $request
  * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function update(UpdateUserProfileRequest $request)
 {
     $user = $this->user();
     // This checks of there's a need to upload the picture and saves the rest of the information if not.
     if ($request->file('profile') == null) {
         $this->repo->updateUser($request, $user);
         return redirect('/')->with('success', 'Profile Successfully updated');
     }
     //Uploads the prof pic and stores it in the database.
     if (!$this->fileRepository->uploadProfilePicture($_FILES['profile'], $request, $user)) {
         return redirect()->back()->withErrors('Profile Was Not Updated, Check if below 10mb or right extension.');
     }
     //Persists the rest of the data.
     $this->repo->updateUser($request, $user);
     return redirect('/');
 }
Exemple #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param UpdateGroupRequest|Request $request
  * @param $group
  * @internal param int $id
  * @return Response
  */
 public function update(UpdateGroupRequest $request, $group)
 {
     if ($request->file('profile') != null) {
         $name = $_FILES['profile']['name'];
         $tmpName = $_FILES['profile']['tmp_name'];
         $location = 'uploads/images/profile/';
         $type = $request->file('profile')->getClientOriginalExtension();
         $rand = $this->fileRepository->randomFileName();
         $destination = $location . $rand . '.' . $type;
         if (move_uploaded_file($tmpName, $destination)) {
             $group->fill($request->input())->save();
             $group->profile()->delete();
             $group->profile()->create(['name' => $name, 'type' => $type, 'source' => $destination]);
             return redirect($group->username)->with('success', 'Profile successfully updated');
         }
         return redirect($group->username)->with('error', 'File has not been uploaded');
     }
     $group->fill($request->input())->save();
     session()->flash('message', 'You have successfully updated your group');
     return redirect($group->username);
 }