Skip to content

Commit 5665465

Browse files
committed
Added option for admins to upload background image for users
1 parent 142fdd0 commit 5665465

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

app/Http/Controllers/AdminController.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ public function editUser(request $request)
220220
$littlelink_name = $request->littlelink_name;
221221
$littlelink_description = $request->littlelink_description;
222222
$role = $request->role;
223+
$customBackground = $request->file('background');
223224

224225
if ($request->password == '') {
225226
User::where('id', $id)->update(['name' => $name, 'email' => $email, 'littlelink_name' => $littlelink_name, 'littlelink_description' => $littlelink_description, 'role' => $role]);
@@ -228,7 +229,19 @@ public function editUser(request $request)
228229
}
229230
if (!empty($profilePhoto)) {
230231
$profilePhoto->move(base_path('/img'), $id . ".png");
231-
}
232+
}
233+
if (!empty($customBackground)) {
234+
$directory = base_path('/img/background-img/');
235+
$files = scandir($directory);
236+
$pathinfo = "error.error";
237+
foreach($files as $file) {
238+
if (strpos($file, $id.'.') !== false) {
239+
$pathinfo = $id. "." . pathinfo($file, PATHINFO_EXTENSION);
240+
}}
241+
if(file_exists(base_path('/img/background-img/').$pathinfo)){File::delete(base_path('/img/background-img/').$pathinfo);}
242+
243+
$customBackground->move(base_path('/img/background-img/'), $id.".".$request->file('background')->extension());
244+
}
232245

233246
return redirect('panel/users/all');
234247
}

resources/views/panel/edit-user.blade.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,19 @@
3737
@endif
3838
@if(file_exists(base_path("img/" . $user->id . ".png")))<br><a title="Remove icon" class="hvr-grow p-1 text-danger" style="padding-left:5px;" href="?delete"><i class="bi bi-trash-fill"></i> Delete</a>@endif
3939
@if($_SERVER['QUERY_STRING'] === 'delete' and File::exists(base_path('img/' . $user->id . '.png')))@php File::delete(base_path('img/' . $user->id . '.png')); header("Location: ".url()->current()); die(); @endphp @endif
40-
</div>
40+
</div><br>
4141

4242
<div class="form-group col-lg-8">
43-
<label>Custom background</label><br>
43+
<label>Custom background</label>
44+
<input type="file" class="form-control-file" name="background">
45+
</div>
46+
<div class="form-group col-lg-8">
4447
@if(!file_exists(base_path('/img/background-img/'.findBackground($user->id))))<p><i>No image selected</i></p>@endif
4548
<img style="width:95%;max-width:400px;argin-left:1rem!important;border-radius:5px;" src="@if(file_exists(base_path('/img/background-img/'.findBackground($user->id)))){{url('/img/background-img/'.findBackground($user->id))}}@else{{url('/littlelink/images/themes/no-preview.png')}}@endif">
4649
@if(file_exists(base_path('/img/background-img/'.findBackground($user->id))))<br><a title="Remove icon" class="hvr-grow p-1 text-danger" style="padding-left:5px;" href="?deleteB"><i class="bi bi-trash-fill"></i> Delete</a>@endif
4750
@if($_SERVER['QUERY_STRING'] === 'deleteB' and File::exists(base_path('/img/background-img/'.findBackground($user->id))))@php File::delete(base_path('/img/background-img/'.findBackground($user->id))); header("Location: ".url()->current()); die(); @endphp @endif
4851
<br>
49-
</div>
52+
</div><br>
5053

5154
<!--<div class="form-group col-lg-8">
5255
<label>Littlelink name </label>

0 commit comments

Comments
 (0)