53 lines
1.7 KiB
PHP
53 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\Homes\UpdateHomeRequest;
|
|
use App\Models\Home;
|
|
use App\Models\Product;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
class HomeController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function edit(): \Illuminate\Contracts\View\View
|
|
{
|
|
$homeModel = Home::query()->firstOrFail();
|
|
$products = Product::query()->where('status', true)->orderBy('label', 'ASC')->get();
|
|
|
|
return view('bo.pages.homes.edit', compact('homeModel', 'products'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\Bo\Homes\UpdateHomeRequest $request
|
|
* @param \App\Models\Home $home
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function update(UpdateHomeRequest $request, Home $home): \Illuminate\Http\RedirectResponse
|
|
{
|
|
return DB::transaction(function () use ($request, $home) {
|
|
$data = $request->validated();
|
|
$home->fill($data);
|
|
if ($home->saveOrFail()) {
|
|
return redirect()
|
|
->route('bo.homes.edit', $home)
|
|
->with('success', trans(
|
|
'crud.messages.has_been_updated',
|
|
['model' => Str::singular(trans('models.classes.homes'))]
|
|
));
|
|
} //end if
|
|
return back()->with('success', trans(
|
|
'crud.messages.cannot_be_updated',
|
|
['model' => Str::singular(trans('models.classes.homes'))]
|
|
));
|
|
});
|
|
}
|
|
}
|