예제 #1
0
 public function upload(Request $request, UploadImage $uploader)
 {
     if ($request->ajax()) {
         if ($request['image']) {
             $file = $request['image'];
             $uploader->upload($file);
             $url = $uploader->getShortUrl();
             $publicId = $uploader->getPublicId();
             $saved = $this->saveImageDetails($url, $publicId);
             if ($saved) {
                 return response()->json(['url' => $url, 'public_id' => $publicId]);
             }
             return response()->json(['message' => 'Error saving image details.']);
         }
         return response()->json(['Message' => 'No image specified']);
     }
     return response()->json(['Error' => 'An unknown error occured, Please try again']);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id, UploadImage $uploader)
 {
     $url = "";
     $user = User::find($id);
     if ($request['file']) {
         //upload file
         $file = $request['file'];
         $uploader->uploadImage($file);
         $url = $uploader->getShortUrl();
     }
     $user->email = $request->get('email');
     $user->name = $request->get('name');
     $user->password = bcrypt($request->get('password'));
     $user->about = $request->get('about');
     $user->avatar_url = $url;
     $user->save();
     return redirect()->action('HomeController@index');
 }