53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Enums\InputType;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\UpdateEngagement;
|
|
use App\Models\Engagement;
|
|
use App\Traits\UpdateModelStatus;
|
|
|
|
class EngagementsController extends Controller
|
|
{
|
|
use UpdateModelStatus;
|
|
|
|
public function index()
|
|
{
|
|
$engagements = Engagement::paginate();
|
|
return view('bo.engagements.index', compact('engagements'));
|
|
}
|
|
|
|
public function edit(Engagement $engagement)
|
|
{
|
|
return view('bo.engagements.edit', ['engagement' => $engagement]);
|
|
}
|
|
|
|
public function update(UpdateEngagement $request, Engagement $engagement)
|
|
{
|
|
$engagement->fill(array_replace_recursive(
|
|
$this->clearImagesAndLabelsArrays($engagement->toArray()),
|
|
$request->validated()
|
|
));
|
|
$engagement->saveOrFail();
|
|
return redirect()->route('bo.engagements.edit', $engagement->id)
|
|
->with('success', 'Enregistré !');
|
|
}
|
|
|
|
private function clearImagesAndLabelsArrays(array $engagement): array
|
|
{
|
|
foreach ($engagement['content'] as &$block) {
|
|
if (isset($block['content'])) {
|
|
foreach ($block['content'] as &$input) {
|
|
if ($input['inputType']['value'] === InputType::imageArray()->value) {
|
|
$input['value'] = [];
|
|
}
|
|
if ($input['inputType']['value'] === InputType::labelArray()->value) {
|
|
$input['value'] = [];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $engagement;
|
|
}
|
|
}
|