56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\StaticPages\UpdateStaticPageRequest;
|
|
use App\Models\StaticPage;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
class StaticPageController extends Controller
|
|
{
|
|
/**
|
|
* Create the controller instance.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->authorizeResource(StaticPage::class);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param \App\Models\StaticPage $static_page
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function edit(StaticPage $static_page): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('bo.pages.static_pages.edit', ['staticPageModel' => $static_page]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\Bo\StaticPages\UpdateStaticPageRequest $request
|
|
* @param \App\Models\StaticPage $static_page
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function update(UpdateStaticPageRequest $request, StaticPage $static_page): \Illuminate\Http\RedirectResponse
|
|
{
|
|
return DB::transaction(function () use ($request, $static_page) {
|
|
$static_page->fill($request->validated());
|
|
|
|
if ($static_page->saveOrFail()) {
|
|
return redirect()->route('bo.static_pages.edit', $static_page)
|
|
->with('success', __('crud.messages.has_been_updated', [
|
|
'model' => Str::ucfirst(\trans_choice('models.classes.static_page', 1))
|
|
]));
|
|
}
|
|
return redirect()->route('bo.static_pages.edit', $static_page)
|
|
->with('error', __('crud.messages.cannot_be_updated', [
|
|
'model' => Str::ucfirst(\trans_choice('models.classes.static_page', 1))
|
|
]));
|
|
});
|
|
}
|
|
}
|