59 lines
2 KiB
PHP
59 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\GeneralConfigs\UpdateGeneralConfigRequest;
|
|
use App\Models\GeneralConfig;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
class GeneralConfigController extends Controller
|
|
{
|
|
/**
|
|
* Edit general config
|
|
*
|
|
* @param \App\Models\GeneralConfig $general_config
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function edit(GeneralConfig $general_config): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('bo.pages.general-configs.edit', [
|
|
'configModel' => $general_config
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Update General
|
|
*
|
|
* @param \App\Http\Requests\Bo\GeneralConfigs\UpdateGeneralConfigRequest $request
|
|
* @param \App\Models\GeneralConfig $general_config
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function update(
|
|
UpdateGeneralConfigRequest $request,
|
|
GeneralConfig $general_config
|
|
): \Illuminate\Http\RedirectResponse {
|
|
$this->authorize('update', $general_config);
|
|
return DB::transaction(function () use ($request, $general_config) {
|
|
$general_config->fill(array_replace_recursive(
|
|
\json_decode(\json_encode($general_config->toArray()), true),
|
|
$request->validated()
|
|
));
|
|
if ($general_config->saveOrFail()) {
|
|
return redirect()
|
|
->route('bo.general_configs.edit', $general_config->getKey())
|
|
->with('success', trans(
|
|
'crud.messages.has_been_updated',
|
|
['model' => Str::ucFirst(Str::singular(trans('models.classes.section')))]
|
|
));
|
|
}
|
|
return redirect()
|
|
->back()
|
|
->with('error', trans(
|
|
'crud.messages.cannot_be_updated',
|
|
['model' => Str::ucFirst(Str::singular(trans('models.classes.section')))]
|
|
));
|
|
});
|
|
}
|
|
}
|