Exemplo n.º 1
0
 public function getOwnerNameAttribute()
 {
     return User::findorFail($this->owner)->name;
 }
Exemplo n.º 2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     //dd($request->newavatarfile);
     //dd(Input::file('newavatarfile'));
     //return $request->all();
     $user = User::findorFail($id);
     $user->name = $request->name;
     $user->email = $request->email;
     $user->superUser = $request->superUser;
     $user->notifyNewTasks = $request->notifyNewTasks;
     $user->notifyNewActions = $request->notifyNewActions;
     $user->notifyNewRisks = $request->notifyNewRisks;
     $user->notifyChangedTasks = $request->notifyChangedTasks;
     $user->notifyChangedActions = $request->notifyChangedActions;
     $user->notifyChangedRisks = $request->notifyChangedRisks;
     $user->notifyDueTasks = $request->notifyDueTasks;
     $user->notifyDueActions = $request->notifyDueActions;
     $user->notifyDueRisks = $request->notifyDueRisks;
     $message = "{$user->name}'s user profile updated successfully";
     if ($request->has('password') && strlen($request->password) > 0) {
         $user->password = bcrypt($request->password);
         $message .= ".  Password has been changed";
     }
     /*        $file = null;
     
                     if(isset($request->newavatarfile)) {
                         $file = $request->newavatarfile;
                     }
                     elseif(isset($request->newavatarurl) && (strlen($request->newavatarurl)>0))
                     {
                         $file = file_get_contents($request->newavatarurl);
                     }
     
                     if($file!=null)
                     {
     
                         $path = public_path()."/img/avatars";
     
                         //return $path;
     
                         $filename = $user->id.'.'.$file->getClientOriginalExtension();
                         $thumbfilename = $user->id.'_thumb.'.$file->getClientOriginalExtension();
     
                         $jpgfullpath = $path.'/'.$user->id.'.jpg';
                         $pngfullpath = $path.'/'.$user->id.'.png';
                         //return $fullpath;
     
                         if(File::exists($jpgfullpath))
                             $delete = File::delete($jpgfullpath);
     
                         if(File::exists($pngfullpath))
                             $delete = File::delete($pngfullpath);
     
     
                         $image = Image::make($file->getRealPath());
     
                         $width = $image->width();
                         $height = $image->height();
     
                         if($width>=$height)
                         {
     
                             $image->resize(null, 500,function ($constraint) {
                                 $constraint->aspectRatio();
                             })
                                 ->crop(500,500)
                                 ->save($path.'/'.$filename)
                                 ->resize(50,50)
                                 ->save($path.'/'.$thumbfilename);
     
                         }
                         else
                         {
                             $image->resize(500, null, function ($constraint) {
                                 $constraint->aspectRatio();
                             })
                                 ->crop(500,500)
                                 ->save($path.'/'.$filename)
                                 ->resize(50,50)
                                 ->save($path.'/'.$thumbfilename);
                         }
     
                         $message .= ".  The profile picture has changed.  You may need to refresh your browser page to see the new picture";
                     }*/
     $image = null;
     if (isset($request->newavatarfile)) {
         $image = Image::make($request->newavatarfile->getRealPath());
     } elseif (isset($request->newavatarurl) && strlen($request->newavatarurl) > 0) {
         $image = Image::make(file_get_contents($request->newavatarurl));
     }
     if ($image != null) {
         $path = public_path() . "/img/avatars/";
         $image->fit(500)->save($path . $user->id . '.png')->fit(50)->save($path . $user->id . '_thumb.png');
         $message .= ".  The profile picture has changed.  You may need to refresh your browser page to see the new picture";
     }
     $user->save();
     flash()->success('Success', $message);
     return redirect(action('UserController@show', [$user->id]));
 }