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

54 lines
2 KiB
PHP

<?php
namespace App\Http\Controllers\Bo;
use App\Http\Controllers\Controller;
use App\Http\Requests\Bo\Convictionpages\UpdateConvictionpageRequest;
use App\Models\Convictionpage;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class ConvictionpageController 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\Convictionpage::class);
/** @var \App\Models\Convictionpage $convictionpageModel */
$convictionpageModel = Convictionpage::query()->firstOrFail();
return view('bo.pages.convictionpages.edit', compact('convictionpageModel'));
}
/**
* Update the specified resource in storage.
*
* @param \App\Http\Requests\Bo\Convictionpages\UpdateConvictionpageRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function update(UpdateConvictionpageRequest $request): \Illuminate\Http\RedirectResponse
{
$this->authorize('update', \App\Models\Convictionpage::class);
return DB::transaction(function () use ($request) {
/** @var \App\Models\Convictionpage $convictionpageModel */
$convictionpageModel = Convictionpage::query()->firstOrFail();
if (($convictionpageModel->fill($request->validated()))->saveOrFail()) {
return redirect()->route('bo.convictionpages.edit')
->with('success', __('crud.messages.has_been_updated', [
'model' => Str::ucfirst(__('models.classes.convictionpage'))
]));
}
return redirect()->route('bo.convictionpages.edit')
->with('error', __('crud.messages.cannot_be_updated', [
'model' => Str::ucfirst(__('models.classes.convictionpage'))
]));
});
}
}