ldc-agis/app/Http/Controllers/Bo/ExplorerpageController.php

62 lines
2.3 KiB
PHP
Raw Permalink Normal View History

2023-10-23 12:14:52 +02:00
<?php
namespace App\Http\Controllers\Bo;
use App\Http\Controllers\Controller;
use App\Http\Requests\Bo\Explorerpage\UpdateExplorerpageRequest;
use App\Models\Commitment;
2023-10-23 12:14:52 +02:00
use App\Models\Explorerpage;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class ExplorerpageController extends Controller
{
/**
* Show the form for editing the specified resource.
2023-10-23 12:14:52 +02:00
*
* @return \Illuminate\Contracts\View\View
*/
public function edit(): \Illuminate\Contracts\View\View
2023-10-23 12:14:52 +02:00
{
$this->authorize('update', \App\Models\Explorerpage::class);
2023-10-23 12:14:52 +02:00
/** @var \App\Models\Explorerpage $explorerpageModel */
$explorerpageModel = Explorerpage::query()->firstOrFail();
2023-10-23 12:14:52 +02:00
/** @var \Illuminate\Database\Eloquent\Collection<array-key, \App\Models\Commitment> */
$commitmentModels = Commitment::all();
2023-10-24 16:54:12 +02:00
return view('bo.pages.explorerpages.edit', compact('explorerpageModel', 'commitmentModels'));
2023-10-23 12:14:52 +02:00
}
/**
* Update the specified resource in storage.
*
* @param \App\Http\Requests\Bo\Explorerpage\UpdateExplorerpageRequest $request
2023-10-23 12:14:52 +02:00
* @return \Illuminate\Http\RedirectResponse
*/
public function update(UpdateExplorerpageRequest $request): \Illuminate\Http\RedirectResponse
{
$this->authorize('update', \App\Models\Explorerpage::class);
return DB::transaction(function () use ($request) {
/** @var \App\Models\Explorerpage $explorerpageModel */
$explorerpageModel = Explorerpage::query()->firstOrFail();
$explorerpageModel->fill($request->safe()->except('commitments'));
$explorerpageModel->commitments()->sync(\collect($request->validated('commitments'))->pluck('id'));
2023-10-23 12:14:52 +02:00
if ($explorerpageModel->saveOrFail()) {
return redirect()->route('bo.explorerpages.edit')
2023-10-23 12:14:52 +02:00
->with('success', __('crud.messages.has_been_updated', [
'model' => Str::ucfirst(__('models.classes.explorerpage'))
]));
}
return redirect()->route('bo.explorerpages.edit')
2023-10-23 12:14:52 +02:00
->with('error', __('crud.messages.cannot_be_updated', [
'model' => Str::ucfirst(__('models.classes.explorerpage'))
]));
});
}
}