Skip to content
Snippets Groups Projects
Verified Commit 8701a5f6 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

feat: update website name retrieval and configuration handling

- Changed the retrieval of the website name in the sidebar component to use the `DbConfig` model for dynamic configuration.
- Updated the `set` method in the `DbConfig` model to allow null values for configuration.
- Refactored the public layout to use the website name from `DbConfig` instead of a hardcoded value.
- Adjusted the default value for maintenance mode and website name in the settings view to match the new configuration method.
- Modified the middleware to check the maintenance mode from the `DbConfig` model.
- Updated the `SettingsController` to use `has` instead of `filled` for checking request inputs related to maintenance mode and website name.
parent 557e8161
No related branches found
No related tags found
1 merge request!64feat: add database configuration management
Pipeline #1090 failed
......@@ -176,11 +176,11 @@ public function updateWebsiteConfig(Request $request): RedirectResponse
->with('error', 'Vous n\'avez pas les droits pour effectuer cette action.');
}
if ($request->filled('maintenance_mode')) {
if ($request->has('maintenance_mode')) {
DbConfig::set('maintenance_mode', $request->maintenance_mode);
}
if ($request->filled('website_name')) {
if ($request->has('website_name')) {
DbConfig::set('website_name', $request->website_name);
}
......
......@@ -2,6 +2,7 @@
namespace App\Http\Middleware;
use App\Models\DbConfig;
use Closure;
use Illuminate\Http\Request;
......@@ -9,7 +10,7 @@ class CheckPrivateModeMiddleware
{
public function handle(Request $request, Closure $next)
{
$privateModeEnabled = config('app.private_mode');
$privateModeEnabled = DbConfig::get('maintenance_mode', 'true');
$privateModeSecret = config('app.private_mode_secret');
$userSecretInput = $request->input('secret');
$secretIsUsable = ! empty($privateModeSecret) && $privateModeSecret === $userSecretInput;
......
......@@ -65,7 +65,7 @@ public static function get(string $key, float|bool|int|string|null $default = nu
* @param string $key The key of the configuration value. Example: 'app.name'
* @param string|int|float|bool $value The value of the configuration.
*/
public static function set(string $key, float|bool|int|string $value): void
public static function set(string $key, float|bool|int|string|null $value): void
{
if (Cache::has('config_'.$key)) {
Cache::forget('config_'.$key);
......@@ -73,6 +73,12 @@ public static function set(string $key, float|bool|int|string $value): void
$config = self::where('key', $key)->first();
if ($value === null) {
$config?->delete();
return;
}
if ($config === null) {
self::create([
'key' => $key,
......
......@@ -30,14 +30,14 @@
name="maintenance_mode"
class="mb-3"
:options="['false' => 'Désactivé', 'true' => 'Activé']"
:selected="old('maintenance_mode', \App\Models\DbConfig::get('maintenance_mode', 'false'))"
:selected="old('maintenance_mode', \App\Models\DbConfig::get('maintenance_mode', 'true'))"
data-form-type="other"
/>
<x-bs.input label="Nom du site internet"
name="website_name"
class="mb-3"
:value="old('website_name', \App\Models\DbConfig::get('website_name', config('app.name')))"
:value="old('website_name', \App\Models\DbConfig::get('website_name', 'Rann Graphic Design'))"
data-form-type="other"
/>
......
......@@ -8,7 +8,7 @@
<a class="website-name" href="{{ route('admin.home') }}">
<img class="logo" src="{{ asset('favicon.svg') }}" alt="Website Logo"/>
<span>
{{ config('app.name') }}
{{ \App\Models\DbConfig::get('website_name', "Rann Graphic Design") }}
</span>
</a>
</div>
......
@php
$websiteName = \App\Models\DbConfig::get('website_name', "Rann Graphic Design")
@endphp
<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ !empty($title) ? $title . ' - Rann Graphic Design' : 'Rann Graphic Design' }}</title>
<title>{{ !empty($title) ? $title . ' - ' . $websiteName : $websiteName }}</title>
<link rel="icon" type="image/svg+xml" href="{{ asset('favicon.svg') }}"/>
<meta property="og:locale" content="{{ config('app.locale') }}">
<meta property="og:locale:alternate" content="{{ config('app.fallback_locale') }}">
<meta property="og:title" content="{{ !empty($title) ? $title : 'Rann Graphic Design' }}">
<meta property="og:title" content="{{ !empty($title) ? $title : $websiteName }}">
<meta property="og:type" content="website">
<meta property="og:url" content="{{ url()->current() }}">
@if(!empty($description))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment