61 lines
2.3 KiB
PHP
61 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\Explorerpage\UpdateExplorerpageRequest;
|
|
use App\Models\Commitment;
|
|
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.
|
|
*
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function edit(): \Illuminate\Contracts\View\View
|
|
{
|
|
$this->authorize('update', \App\Models\Explorerpage::class);
|
|
|
|
/** @var \App\Models\Explorerpage $explorerpageModel */
|
|
$explorerpageModel = Explorerpage::query()->firstOrFail();
|
|
|
|
/** @var \Illuminate\Database\Eloquent\Collection<array-key, \App\Models\Commitment> */
|
|
$commitmentModels = Commitment::all();
|
|
|
|
return view('bo.pages.explorerpages.edit', compact('explorerpageModel', 'commitmentModels'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\Bo\Explorerpage\UpdateExplorerpageRequest $request
|
|
* @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'));
|
|
|
|
if ($explorerpageModel->saveOrFail()) {
|
|
return redirect()->route('bo.explorerpages.edit')
|
|
->with('success', __('crud.messages.has_been_updated', [
|
|
'model' => Str::ucfirst(__('models.classes.explorerpage'))
|
|
]));
|
|
}
|
|
return redirect()->route('bo.explorerpages.edit')
|
|
->with('error', __('crud.messages.cannot_be_updated', [
|
|
'model' => Str::ucfirst(__('models.classes.explorerpage'))
|
|
]));
|
|
});
|
|
}
|
|
}
|