Merge branch 'session-data' into 'laravel-10'
refactor: ♻️ replace saving theme/pagination/lang in cache by session
See merge request ldc-web/projets/laravel-base-project!52
This commit is contained in:
commit
fb997768dc
6 changed files with 21 additions and 21 deletions
|
|
@ -10,7 +10,6 @@ use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Str;
|
||||
|
|
@ -206,12 +205,12 @@ class Controller extends BaseController
|
|||
$cacheKey = "pagination.{$currentRoutePath}";
|
||||
$pagination = $pagination ?? ItemsPerPaginationEnum::twelve;
|
||||
$pagination = ToolboxHelper::getValidatedEnum(
|
||||
Cache::get($cacheKey, $pagination->value()),
|
||||
Session::get($cacheKey, $pagination->value()),
|
||||
'pagination',
|
||||
'\App\Enums\Pagination\ItemsPerPaginationEnum',
|
||||
);
|
||||
if (Cache::get($cacheKey) !== $pagination) {
|
||||
Cache::put($cacheKey, $pagination);
|
||||
if (Session::get($cacheKey) !== $pagination) {
|
||||
Session::put($cacheKey, $pagination);
|
||||
}
|
||||
$query = $query->paginate($pagination);
|
||||
return $query;
|
||||
|
|
@ -226,12 +225,12 @@ class Controller extends BaseController
|
|||
protected function setTheme(Request $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
$theme = ToolboxHelper::getValidatedEnum(
|
||||
$request->theme ?: Cache::get('theme', BootstrapThemeEnum::light->value()),
|
||||
$request->theme ?: Session::get('theme', BootstrapThemeEnum::light->value()),
|
||||
'theme',
|
||||
'\App\Http\Controllers\BootstrapThemeEnum',
|
||||
'\App\Enums\Theme\BootstrapThemeEnum',
|
||||
);
|
||||
if (Cache::get("theme") !== $theme) {
|
||||
Cache::put("theme", $theme);
|
||||
if (Session::get('theme') !== $theme) {
|
||||
Session::put('theme', $theme);
|
||||
}
|
||||
return redirect()->back()->with('success', __('crud.messages.theme_updated'));
|
||||
}
|
||||
|
|
|
|||
6
package-lock.json
generated
6
package-lock.json
generated
|
|
@ -2707,9 +2707,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/caniuse-lite": {
|
||||
"version": "1.0.30001600",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001600.tgz",
|
||||
"integrity": "sha512-+2S9/2JFhYmYaDpZvo0lKkfvuKIglrx68MwOBqMGHhQsNkLjB5xtc/TGoEPs+MxjSyN/72qer2g97nzR641mOQ==",
|
||||
"version": "1.0.30001687",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001687.tgz",
|
||||
"integrity": "sha512-0S/FDhf4ZiqrTUiQ39dKeUjYRjkv7lOZU1Dgif2rIqrTzX/1wV2hfKu9TOm1IHkdSijfLswxTFzl/cvir+SLSQ==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
@use('\App\Enums\Theme\BootstrapThemeEnum', 'BootstrapThemeEnum')
|
||||
|
||||
<body data-bs-theme="{{ (BootstrapThemeEnum::make(intval(cache()->get('theme'))) ?? BootstrapThemeEnum::light)->name() }}">
|
||||
<body data-bs-theme="{{ (BootstrapThemeEnum::make(intval(session()->get("theme"))) ?? BootstrapThemeEnum::light)->name() }}">
|
||||
<!-- Navigation -->
|
||||
@include('bo.layouts.header')
|
||||
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@
|
|||
<input class="d-none form-check-input" id="theme{{ $key }}" name="theme" type="radio"
|
||||
value="{{ $bootstrapTheme->value }}">
|
||||
<label class="dropdown-item w-100 text-decoration-none @if (
|
||||
!is_null(cache()->get('theme'))
|
||||
? $bootstrapTheme->value === intval(cache()->get('theme'))
|
||||
!is_null(session()->get("theme"))
|
||||
? $bootstrapTheme->value === intval(session()->get("theme"))
|
||||
: $bootstrapTheme->value === BootstrapThemeEnum::light->value) active @endif p-2"
|
||||
for="theme{{ $key }}" role="button">
|
||||
{{ str($bootstrapTheme->label)->ucFirst() }}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
{{-- GET ACTUAL PAGINATION --}}
|
||||
@php $pagination = intval(cache()->get('pagination.' . str()->slug(request()->route()->getName()))); @endphp
|
||||
@php $pagination = intval(session()->get('pagination.' . str()->slug(request()->route()->getName()))); @endphp
|
||||
@if ($paginator->items())
|
||||
<nav class="pagination-custom d-flex justify-content-between align-items-center">
|
||||
{{-- SELECT ITEMS PER PAGE --}}
|
||||
|
|
|
|||
|
|
@ -33,19 +33,20 @@
|
|||
@endif
|
||||
</td>
|
||||
@php
|
||||
$targetModel = $activitylogModel->model_class
|
||||
::where((new $activitylogModel->model_class())->getRouteKeyName(), $activitylogModel->model_id)
|
||||
->first();
|
||||
$targetModel = $activitylogModel->model_class::where(
|
||||
(new $activitylogModel->model_class())->getRouteKeyName(),
|
||||
$activitylogModel->model_id
|
||||
)->first();
|
||||
$editRouteName = 'bo.' . optional($targetModel)->getTable() . '.edit';
|
||||
@endphp
|
||||
<td class="bg-{{ $activitylogModel->event->bootstrapClass() }}-subtle text-center align-middle">
|
||||
@if (!empty($targetModel) and route()->has($editRouteName))
|
||||
@if (!empty($targetModel) and request()->is($editRouteName))
|
||||
<a class="btn btn-sm btn-primary text-decoration-none" data-bs-toggle="tooltip"
|
||||
href="{{ route($editRouteName, $activitylogModel->model_id) }}"
|
||||
title="{{ __('crud.helpers.view_model', ['model' => __('models.classes.' . str($targetModel->getTable())->singular())]) }}">
|
||||
title="{{ __('crud.helpers.view_model', ['model' => trans_choice('models.classes.' . str($targetModel->getTable())->singular(), 1)]) }}">
|
||||
@endif
|
||||
{{ $activitylogModel->model_class }}
|
||||
@if (!empty($targetModel) and route()->has($editRouteName))
|
||||
@if (!empty($targetModel) and request()->is($editRouteName))
|
||||
</a>
|
||||
@endif
|
||||
</td>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue