Ignore:
Timestamp:
10/13/21 15:44:57 (3 years ago)
Author:
Berat Kjufliju <kufliju@…>
Branches:
develop, master
Children:
120759b
Parents:
194a359
Message:

added documents crud, added last_seen_to_user, edited views

File:
1 edited

Legend:

Unmodified
Added
Removed
  • app/Http/Controllers/Dashboard/UsersController.php

    r194a359 r24a616f  
    55use App\Helpers\Alert;
    66use App\Http\Requests\Dashboard\NewUserRequest;
     7use App\Http\Requests\Dashboard\UpdateUserData;
    78use App\Http\Requests\Dashboard\UpdateUserRequest;
     9use App\Models\Avatar;
     10use Illuminate\Support\Facades\File;
    811use App\Models\Role;
    912use App\Models\User;
     
    1215use App\Notifications\WelcomeUser;
    1316use App\Http\Controllers\Controller;
     17use Illuminate\Support\Facades\Storage;
    1418
    1519class UsersController extends Controller
    1620{
     21
    1722    public function index()
    1823    {
     
    4449        $user->role_id = $request->userRole;
    4550
     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        }
    4663        $user->save();
    4764
     
    7087        $user->mobile_number = $request->mobile_number;
    7188        $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
    72103        if($user->isDirty('email')) {
    73104            $user->notify(new VerifyNewEmail($user));
     
    78109
    79110        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");
    94111    }
    95112
     
    129146      return $roles;
    130147    }
     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    }
    131175}
Note: See TracChangeset for help on using the changeset viewer.