Merge pull request #279 from ControlPanel-gg/icon_upload
Fixed the file uploads in settings
This commit is contained in:
commit
6c42ac1a88
|
@ -8,7 +8,6 @@ use Illuminate\Contracts\View\Factory;
|
||||||
use Illuminate\Contracts\View\View;
|
use Illuminate\Contracts\View\View;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
|
|
||||||
class SettingsController extends Controller
|
class SettingsController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -22,25 +21,20 @@ class SettingsController extends Controller
|
||||||
return view('admin.settings.index');
|
return view('admin.settings.index');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateIcons(Request $request){
|
public function updateIcons(Request $request)
|
||||||
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'favicon' => 'required',
|
'icon' => 'nullable|max:10000|mimes:jpg,png,jpeg',
|
||||||
'icon' => 'required',
|
'favicon' => 'nullable|max:10000|mimes:ico',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//store favicon
|
if ($request->hasFile('icon')) {
|
||||||
$favicon = $request->input('favicon');
|
$request->file('icon')->storeAs('public', 'icon.png');
|
||||||
$favicon = json_decode($favicon);
|
}
|
||||||
$favicon = explode(",",$favicon->output->image)[1];
|
|
||||||
Storage::disk('public')->put('favicon.ico' , base64_decode($favicon));
|
|
||||||
|
|
||||||
//store dashboard icon
|
if ($request->hasFile('favicon')) {
|
||||||
$icon = $request->input('icon');
|
$request->file('favicon')->storeAs('public', 'favicon.ico');
|
||||||
$icon = json_decode($icon);
|
}
|
||||||
$icon = explode(",",$icon->output->image)[1];
|
|
||||||
|
|
||||||
Storage::disk('public')->put('icon.png' , base64_decode($icon));
|
|
||||||
|
|
||||||
return redirect()->route('admin.settings.index')->with('success', 'Icons updated!');
|
return redirect()->route('admin.settings.index')->with('success', 'Icons updated!');
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,41 +45,38 @@
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div class="tab-pane mt-3 active" id="dashboard-icons">
|
<div class="tab-pane mt-3 active" id="dashboard-icons">
|
||||||
|
|
||||||
<form method="POST" class="mb-3" action="{{route('admin.settings.update.icons')}}">
|
<form method="POST" enctype="multipart/form-data" class="mb-3"
|
||||||
|
action="{{route('admin.settings.update.icons')}}">
|
||||||
@csrf
|
@csrf
|
||||||
@method('PATCH')
|
@method('PATCH')
|
||||||
|
|
||||||
<div class="d-flex">
|
<div class="row">
|
||||||
<div class="form-group">
|
<div class="col-md-6 col-lg-4 col-12">
|
||||||
<div class="text-center mb-2">Dashboard Icon</div>
|
<div class="form-group">
|
||||||
<div class="avatar">
|
<div class="custom-file mb-3 mt-3">
|
||||||
<div class="slim rounded-circle"
|
<input type="file" accept="image/png,image/jpeg,image/jpg"
|
||||||
data-size="128,128"
|
class="custom-file-input" name="icon" id="icon">
|
||||||
data-ratio="1:1"
|
<label class="custom-file-label selected"
|
||||||
style="width: 140px;height:140px; cursor: pointer"
|
for="icon">{{__('Select panel icon')}}</label>
|
||||||
data-save-initial-image="true">
|
|
||||||
<input type="file" name="icon"/>
|
|
||||||
<img
|
|
||||||
src="{{\Illuminate\Support\Facades\Storage::disk('public')->exists('icon.png') ? asset('storage/icon.png') : asset('images/bitsec.png')}}"
|
|
||||||
alt="icon">
|
|
||||||
</div>
|
</div>
|
||||||
|
@error('icon')
|
||||||
|
<span class="text-danger">
|
||||||
|
{{$message}}
|
||||||
|
</span>
|
||||||
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="form-group">
|
||||||
|
<div class="custom-file mb-3">
|
||||||
|
<input type="file" accept="image/x-icon" class="custom-file-input"
|
||||||
<div class="form-group ml-5">
|
name="favicon" id="favicon">
|
||||||
<div class="text-center mb-2">Favicon</div>
|
<label class="custom-file-label selected"
|
||||||
<div class="avatar">
|
for="favicon">{{__('Select panel favicon')}}</label>
|
||||||
<div class="slim rounded-circle"
|
|
||||||
data-size="64,64"
|
|
||||||
data-ratio="1:1"
|
|
||||||
style="width: 140px;height:140px; cursor: pointer"
|
|
||||||
data-save-initial-image="true">
|
|
||||||
<input accept="image/x-icon" type="file" name="favicon"/>
|
|
||||||
<img
|
|
||||||
src="{{\Illuminate\Support\Facades\Storage::disk('public')->exists('favicon.ico') ? asset('storage/favicon.ico') : asset('favicon.ico')}}"
|
|
||||||
alt="favicon">
|
|
||||||
</div>
|
</div>
|
||||||
|
@error('favicon')
|
||||||
|
<span class="text-danger">
|
||||||
|
{{$message}}
|
||||||
|
</span>
|
||||||
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -87,7 +84,8 @@
|
||||||
<button class="btn btn-primary">Submit</button>
|
<button class="btn btn-primary">Submit</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<p class="text-muted">Images and Icons may be cached, use <code>CNTRL + F5</code><sup>(google chrome hotkey)</sup> to reload without cache to see your changes appear :)</p>
|
<p class="text-muted">Images and Icons may be cached, use <code>CNTRL + F5</code><sup>(google
|
||||||
|
chrome hotkey)</sup> to reload without cache to see your changes appear :)</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -103,7 +101,15 @@
|
||||||
</section>
|
</section>
|
||||||
<!-- END CONTENT -->
|
<!-- END CONTENT -->
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Add the following code if you want the name of the file appear on select
|
||||||
|
document.addEventListener('DOMContentLoaded', ()=>{
|
||||||
|
$(".custom-file-input").on("change", function () {
|
||||||
|
var fileName = $(this).val().split("\\").pop();
|
||||||
|
$(this).siblings(".custom-file-label").addClass("selected").html(fileName);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
@endsection
|
@endsection
|
||||||
|
|
Loading…
Reference in a new issue