diff --git a/app/Enums/GeneralConfigType.php b/app/Enums/GeneralConfigType.php new file mode 100644 index 00000000..0f2e01dd --- /dev/null +++ b/app/Enums/GeneralConfigType.php @@ -0,0 +1,25 @@ + 1 + ]; + } + + protected static function labels(): array + { + return [ + 'actu' => __('Actualité') + ]; + } +} diff --git a/app/Http/Controllers/Bo/GeneralConfig.php b/app/Http/Controllers/Bo/GeneralConfig.php new file mode 100644 index 00000000..faba7c9b --- /dev/null +++ b/app/Http/Controllers/Bo/GeneralConfig.php @@ -0,0 +1,32 @@ + $config]); + } + + public function update(UpdateGeneralConfig $request, ModelsGeneralConfig $config) + { + $config->fill(array_replace_recursive( + $config->toArray(), + $request->validated() + )); + $config->saveOrFail(); + return redirect()->route('bo.general-configs.edit', $config) + ->with('success', 'Enregistré !'); + } +} diff --git a/app/Http/Requests/UpdateGeneralConfig.php b/app/Http/Requests/UpdateGeneralConfig.php new file mode 100644 index 00000000..0458b4ba --- /dev/null +++ b/app/Http/Requests/UpdateGeneralConfig.php @@ -0,0 +1,9 @@ + GeneralConfigType::class + ]; + + protected $casts = [ + 'data' => 'array' + ]; + + protected $primaryKey = 'type'; + + public $incrementing = false; + + protected $fillable = [ + 'type', 'data' + ]; +} diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index a9848800..0784d98a 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -3,6 +3,7 @@ namespace App\Providers; use App\Enums\ArticleCategory; +use App\Enums\GeneralConfigType; use App\Models\Actu; use App\Models\Ads; use App\Models\Articles; @@ -11,6 +12,7 @@ use App\Models\BreederPortrait; use App\Models\ConsumptionTimes; use App\Models\Engagement; use App\Models\FaqQuestions; +use App\Models\GeneralConfig; use App\Models\HomeSliderPictures; use App\Models\MeatTypes; use App\Models\Moments; @@ -140,6 +142,19 @@ class RouteServiceProvider extends ServiceProvider Route::bind('ocb', function ($value) { return OCBContent::where('id', $value)->firstOrFail(); }); + Route::bind('general_config', function ($value) { + try { + $value = \ctype_digit($value) ? \intval($value) : $value; + foreach (GeneralConfigType::toArray() as $config) { + if ($config->value === $value) { + return GeneralConfig::where('type', $value)->firstOrFail(); + } + } + abort(404); + } catch (BadMethodCallException | EnumNotRoutableException $e) { + return null; + } + }); parent::boot(); } diff --git a/config/app.php b/config/app.php index 332a222b..60a43b1b 100644 --- a/config/app.php +++ b/config/app.php @@ -257,7 +257,8 @@ return [ 'NotificationType' => \App\Enums\NotificationType::class, 'EngagementType' => \App\Enums\EngagementType::class, 'EngagementBlocType' => \App\Enums\EngagementBlocType::class, - 'InputType' => \App\Enums\InputType::class + 'InputType' => \App\Enums\InputType::class, + 'GeneralConfigType' => \App\Enums\GeneralConfigType::class ], ]; diff --git a/database/migrations/2021_09_18_081831_create_general_configs_table.php b/database/migrations/2021_09_18_081831_create_general_configs_table.php new file mode 100644 index 00000000..dec6f960 --- /dev/null +++ b/database/migrations/2021_09_18_081831_create_general_configs_table.php @@ -0,0 +1,51 @@ +smallInteger('type')->primary(); // GeneralConfigType + + $table->mediumText('data'); // json + + $table->timestamps(); + }); + + $config = new GeneralConfig([ + 'type' => GeneralConfigType::actu(), + 'data' => [ + 'img_actu_header' => [ + 'dimensions' => 'largeur 1920,hauteur 440', + 'label' => 'Image d\'entête actualités', + 'inputType' => InputType::image(), + 'alt' => 'Image d\'entête actualités', + 'value' => '/assets/images/actu/le-gaulois-actualites-header.jpg' + ] + ] + ]); + $config->saveOrFail(); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('general_configs'); + } +} diff --git a/resources/assets/images/actu/le-gaulois-actualites-header.jpg b/resources/assets/images/actu/le-gaulois-actualites-header.jpg new file mode 100644 index 00000000..89a662f5 Binary files /dev/null and b/resources/assets/images/actu/le-gaulois-actualites-header.jpg differ diff --git a/resources/views/bo/general-configs/edit.blade.php b/resources/views/bo/general-configs/edit.blade.php new file mode 100644 index 00000000..01d148b0 --- /dev/null +++ b/resources/views/bo/general-configs/edit.blade.php @@ -0,0 +1,24 @@ +@extends('layouts.bo') + +@section('content') +
+
+ {{ __('Modification d\'une configuration') }} + {{ __('Retour') }} +
+
+
+ @method('PUT') + @csrf +
+
+ @include('bo.modules.minicrud-form-inputs', ['model' => $config]) +
+ +
+
+
+
+
+
+@endsection diff --git a/resources/views/bo/general-configs/index.blade.php b/resources/views/bo/general-configs/index.blade.php new file mode 100644 index 00000000..30f55848 --- /dev/null +++ b/resources/views/bo/general-configs/index.blade.php @@ -0,0 +1,31 @@ +@extends('layouts.bo') + +@section('content') +
+
+ {{ __('Liste des configurations') }} +
+ +
+ {{ $configs->withQueryString()->links() }} + + + @include('bo.modules.tableColSorter', [ + 'cols' => [ + 'type' => 'Type' + ] + ]) + + + @foreach($configs as $config) + + + + + @endforeach + +
{{$config->type}}{{ __('Éditer') }}
+ {{ $configs->withQueryString()->links() }} +
+
+@endsection diff --git a/resources/views/layouts/bo.blade.php b/resources/views/layouts/bo.blade.php index 33c6164f..bf323371 100644 --- a/resources/views/layouts/bo.blade.php +++ b/resources/views/layouts/bo.blade.php @@ -81,6 +81,13 @@