General config system
This commit is contained in:
parent
178d41b519
commit
2a248e89de
12 changed files with 227 additions and 2 deletions
25
app/Enums/GeneralConfigType.php
Normal file
25
app/Enums/GeneralConfigType.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Kwaadpepper\Enum\BaseEnumRoutable;
|
||||
|
||||
/**
|
||||
* @method static self actu()
|
||||
*/
|
||||
final class GeneralConfigType extends BaseEnumRoutable
|
||||
{
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'actu' => 1
|
||||
];
|
||||
}
|
||||
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'actu' => __('Actualité')
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Http/Controllers/Bo/GeneralConfig.php
Normal file
32
app/Http/Controllers/Bo/GeneralConfig.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\UpdateGeneralConfig;
|
||||
use App\Models\GeneralConfig as ModelsGeneralConfig;
|
||||
|
||||
class GeneralConfig extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$configs = ModelsGeneralConfig::paginate();
|
||||
return view('bo.general-configs.index', compact('configs'));
|
||||
}
|
||||
|
||||
public function edit(ModelsGeneralConfig $config)
|
||||
{
|
||||
return view('bo.general-configs.edit', ['config' => $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é !');
|
||||
}
|
||||
}
|
||||
9
app/Http/Requests/UpdateGeneralConfig.php
Normal file
9
app/Http/Requests/UpdateGeneralConfig.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
class UpdateGeneralConfig extends UpdateMiniCrudRequest
|
||||
{
|
||||
|
||||
protected $modelName = 'general_config';
|
||||
}
|
||||
30
app/Models/GeneralConfig.php
Normal file
30
app/Models/GeneralConfig.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\GeneralConfigType;
|
||||
use App\Traits\MiniCrudModel;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Kwaadpepper\Enum\Traits\CastsEnums;
|
||||
|
||||
class GeneralConfig extends Model
|
||||
{
|
||||
use CastsEnums;
|
||||
use MiniCrudModel;
|
||||
|
||||
protected $enumCasts = [
|
||||
'type' => GeneralConfigType::class
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'data' => 'array'
|
||||
];
|
||||
|
||||
protected $primaryKey = 'type';
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $fillable = [
|
||||
'type', 'data'
|
||||
];
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
],
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\GeneralConfigType;
|
||||
use App\Enums\InputType;
|
||||
use App\Models\GeneralConfig;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateGeneralConfigsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('general_configs', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
}
|
||||
BIN
resources/assets/images/actu/le-gaulois-actualites-header.jpg
Normal file
BIN
resources/assets/images/actu/le-gaulois-actualites-header.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
24
resources/views/bo/general-configs/edit.blade.php
Normal file
24
resources/views/bo/general-configs/edit.blade.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
@extends('layouts.bo')
|
||||
|
||||
@section('content')
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
{{ __('Modification d\'une configuration') }}
|
||||
<a href="{{route('bo.general-configs.index')}}" class="btn btn-sm btn-primary float-right ml-2">{{ __('Retour') }}</a>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="{{route('bo.general-configs.update', $config)}}" method="POST" enctype="multipart/form-data">
|
||||
@method('PUT')
|
||||
@csrf
|
||||
<div class="row">
|
||||
<div class="col-md-8 offset-md-2">
|
||||
@include('bo.modules.minicrud-form-inputs', ['model' => $config])
|
||||
<div class="form-group text-center">
|
||||
<input type="submit" class="btn btn-secondary" value="{{ __('Modifier') }}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
31
resources/views/bo/general-configs/index.blade.php
Normal file
31
resources/views/bo/general-configs/index.blade.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
@extends('layouts.bo')
|
||||
|
||||
@section('content')
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
{{ __('Liste des configurations') }}
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
{{ $configs->withQueryString()->links() }}
|
||||
<table class="table text-center">
|
||||
<thead class="thead-dark">
|
||||
@include('bo.modules.tableColSorter', [
|
||||
'cols' => [
|
||||
'type' => 'Type'
|
||||
]
|
||||
])
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($configs as $config)
|
||||
<tr>
|
||||
<td>{{$config->type}}</td>
|
||||
<td><a href="{{route('bo.general-configs.edit', $config)}}" class="btn btn-sm btn-primary">{{ __('Éditer') }}</a></td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
{{ $configs->withQueryString()->links() }}
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
|
@ -81,6 +81,13 @@
|
|||
<div class="col-md-2">
|
||||
<nav class="nav flex-column sticky-top">
|
||||
<a class="nav-link" href="{{route('bo.dashboard')}}">{{ __('Tableau de bord') }}</a>
|
||||
{{-- Actus --}}
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">{{ __('Actus') }}</a>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="{{route('bo.general-configs.edit', GeneralConfigType::actu()->value)}}">{{ __('Configuration') }}</a>
|
||||
</div>
|
||||
</li>
|
||||
{{-- En ce moment --}}
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">{{ __('En ce moment') }}</a>
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ Route::prefix('bo')
|
|||
Route::resource('engagements', BoEngagementsController::class)->except(['show', 'create', 'store', 'destroy'])
|
||||
->withoutMiddleware('xss')
|
||||
->middleware('xss:content,title,value,text,bigText');
|
||||
Route::resource('general-config', BoGeneralConfig::class)->except(['index', 'show', 'create', 'destroy']);
|
||||
Route::resource('general-configs', BoGeneralConfig::class)->except(['show', 'create', 'store', 'destroy']);
|
||||
});
|
||||
|
||||
Route::get('/', [BoDashboardController::class, 'index'])->name('dashboard');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue