Changeset 24a616f for app/Http/Controllers/Dashboard/UsersController.php
- Timestamp:
- 10/13/21 15:44:57 (3 years ago)
- Branches:
- develop, master
- Children:
- 120759b
- Parents:
- 194a359
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
app/Http/Controllers/Dashboard/UsersController.php
r194a359 r24a616f 5 5 use App\Helpers\Alert; 6 6 use App\Http\Requests\Dashboard\NewUserRequest; 7 use App\Http\Requests\Dashboard\UpdateUserData; 7 8 use App\Http\Requests\Dashboard\UpdateUserRequest; 9 use App\Models\Avatar; 10 use Illuminate\Support\Facades\File; 8 11 use App\Models\Role; 9 12 use App\Models\User; … … 12 15 use App\Notifications\WelcomeUser; 13 16 use App\Http\Controllers\Controller; 17 use Illuminate\Support\Facades\Storage; 14 18 15 19 class UsersController extends Controller 16 20 { 21 17 22 public function index() 18 23 { … … 44 49 $user->role_id = $request->userRole; 45 50 51 if ($request->hasFile("avatar")) { 52 $image = $request->file("avatar"); 53 $avatarName = $user->id . '_avatar' . time() . '.' . request()->avatar->getClientOriginalExtension(); 54 55 if (!empty($user->avatar)) { 56 Storage::disk('uploads')->delete("/users/" . $user->avatar); 57 } 58 59 Storage::disk('uploads')->put("/users/" . $avatarName, File::get($image)); 60 61 $user->avatar = $avatarName; 62 } 46 63 $user->save(); 47 64 … … 70 87 $user->mobile_number = $request->mobile_number; 71 88 $user->role_id = $request->userRole; 89 90 if ($request->hasFile("avatar")) { 91 $image = $request->file("avatar"); 92 $avatarName = $user->id . '_avatar' . time() . '.' . request()->avatar->getClientOriginalExtension(); 93 94 if (!empty($user->avatar)) { 95 Storage::disk('uploads')->delete("/users/" . $user->avatar); 96 } 97 98 Storage::disk('uploads')->put("/users/" . $avatarName, File::get($image)); 99 100 $user->avatar = $avatarName; 101 } 102 72 103 if($user->isDirty('email')) { 73 104 $user->notify(new VerifyNewEmail($user)); … … 78 109 79 110 return redirect()->route("dashboard.users.index"); 80 }81 82 public function editUserData(UpdateUserRequest $request, $id)83 {84 $user = User::findOrFail($id);85 $user->name = $request->name;86 $user->surname = $request->surname;87 $user->mobile_number = $request->mobile_number;88 89 $user->save();90 91 Alert::flash("User data updated successfully");92 93 return redirect()->route("dashboard.settings.index");94 111 } 95 112 … … 129 146 return $roles; 130 147 } 148 149 public function editUserData(UpdateUserData $request, $id) 150 { 151 $user = User::findOrFail($id); 152 $user->name = $request->name; 153 $user->surname = $request->surname; 154 $user->mobile_number = $request->mobile_number; 155 156 if ($request->hasFile("avatar")) { 157 $image = $request->file("avatar"); 158 $avatarName = $user->id . '_avatar' . time() . '.' . request()->avatar->getClientOriginalExtension(); 159 160 if (!empty($user->avatar)) { 161 Storage::disk('uploads')->delete("/users/" . $user->avatar); 162 } 163 164 Storage::disk('uploads')->put("/users/" . $avatarName, File::get($image)); 165 166 $user->avatar = $avatarName; 167 } 168 169 $user->save(); 170 171 Alert::flash("User data updated successfully"); 172 173 return redirect()->route("dashboard.settings.index"); 174 } 131 175 }
Note:
See TracChangeset
for help on using the changeset viewer.