Ignore:
Timestamp:
10/24/21 20:55:11 (3 years ago)
Author:
beratkjufliju <kufliju@…>
Branches:
develop, master
Children:
7043def
Parents:
e0d3f94
Message:

bug fixes

File:
1 edited

Legend:

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

    re0d3f94 r0df7a93  
    88use App\Http\Requests\Dashboard\UpdateUserRequest;
    99use App\Models\Avatar;
     10use App\Models\Department;
     11use App\Models\Folder;
    1012use Carbon\Carbon;
    1113use Illuminate\Support\Facades\File;
     
    2628            "users" => User::all(),
    2729            "roles" => Role::all(),
     30            "adminAndReferents" => User::where("role_id", 1)->orWhere("role_id", 2)->get()
    2831        ]);
    2932    }
     
    138141        $user = User::find($id);
    139142
    140         $user->userProfile->delete();
    141         $user->delete();
     143        if(Folder::where('user_id', $user->id)->count() == 0) {
     144            if (Storage::disk("uploads")->exists("users" . DIRECTORY_SEPARATOR . $user->avatar)) {
     145                Storage::disk("uploads")->delete("users" . DIRECTORY_SEPARATOR . $user->avatar);
     146            }
    142147
    143         Alert::flash($user->name . " deleted successfully");
     148            $user->delete();
    144149
    145         return redirect()->route("dashboard.users.index");
     150            Alert::flash($user->name . " deleted successfully");
     151
     152            return redirect()->route("dashboard.users.index");
     153        }
     154        else {
     155            Alert::flash($user->name . "has associated folders");
     156
     157            return redirect()->back();
     158        }
    146159    }
    147160
Note: See TracChangeset for help on using the changeset viewer.