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

Location:
app/Http/Controllers/Dashboard
Files:
1 added
4 edited

Legend:

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

    r194a359 r24a616f  
    1111use App\Http\Controllers\Controller;
    1212use Illuminate\Support\Facades\Auth;
     13use Illuminate\Support\Facades\Storage;
    1314
    1415class DepartmentsController extends Controller
     
    1718    {
    1819        return view("dashboard.departments.index")->with([
    19             "departments" => Department::all()
     20            "departments" => Department::all(),
    2021        ]);
    2122    }
     
    3738        $department = Department::findOrFail($id);
    3839
     40        $oldDepartmentCode = $department->code;
     41
    3942        $department->name = $request->name;
    4043        $department->code = $request->code;
     44
     45        $path = '/Departments/' . $request->code;
     46        $department->location = $path;
     47
     48        $files = Storage::allFiles($oldDepartmentCode);
     49
     50        if($department->isDirty('code'))
     51        {
     52            if(!Storage::disk('local')->has('Departments/' . $request->code)){
     53                Storage::disk('local')->move('Departments/' . $oldDepartmentCode, 'Departments/' . $department->code);
     54            }
     55        }
    4156
    4257        $department->save();
     
    5469        $department->code = $request->code;
    5570
     71        if(!Storage::disk('local')->has('Departments/' . $request->code)){
     72            Storage::disk('local')->makeDirectory('Departments/' . $request->code);
     73        }
     74
    5675        $department->user_id = auth()->id();
     76        $department->location = '/Departments/' . $request->code;
     77
     78        dd($department->location);
    5779
    5880        $department->save();
  • app/Http/Controllers/Dashboard/IndexController.php

    r194a359 r24a616f  
    1515        );
    1616
    17         Alert::flash("test");
    18 
    1917        return view("dashboard.index")->with([
    2018            "counters" => $counters,
  • app/Http/Controllers/Dashboard/SettingsController.php

    r194a359 r24a616f  
    99use App\Http\Requests\Dashboard\PhotosSettingsRequest;
    1010use App\Http\Requests\Dashboard\SocialLinksSettingsRequest;
     11use App\Http\Requests\Dashboard\UpdateUserData;
     12use App\Http\Requests\Dashboard\UpdateUserRequest;
    1113use App\Http\Requests\Dashboard\UsernameSettingsRequest;
    1214use App\Http\Requests\Dashboard\UserProfileSettingsRequest;
     
    7880    }
    7981
    80 
    81 
    8282}
  • 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.