141 lines
4.8 KiB
PHP
141 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\ExpertiseProducts\StoreExpertiseProductRequest;
|
|
use App\Http\Requests\Bo\ExpertiseProducts\UpdateExpertiseProductRequest;
|
|
use App\Models\ExpertiseProduct;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
class ExpertiseProductController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function index(Request $request): \Illuminate\Contracts\View\View
|
|
{
|
|
/** @var \Illuminate\Database\Eloquent\Builder $vipModels */
|
|
$vipModels = ExpertiseProduct::query();
|
|
|
|
/** @var string $search Search field */
|
|
$search = $request->search;
|
|
if ($search) {
|
|
$this->searchQuery(
|
|
$vipModels,
|
|
$search,
|
|
null,
|
|
'label',
|
|
'title'
|
|
);
|
|
}
|
|
$searchFields = trans('Libellé, Titre');
|
|
|
|
/** Sort columns with a query */
|
|
$this->sortQuery($vipModels);
|
|
|
|
/** Custom pagination */
|
|
$vipModels = $this->paginate($vipModels);
|
|
|
|
return view('bo.pages.vips.index', compact('vipModels', 'search', 'searchFields'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @param \App\Models\ExpertiseProduct $vip
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function create(ExpertiseProduct $vip): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('bo.pages.vips.create', ['vipModel' => $vip]);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\Bo\ExpertiseProducts\StoreExpertiseProductRequest $request
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function store(StoreExpertiseProductRequest $request): \Illuminate\Http\RedirectResponse
|
|
{
|
|
return DB::transaction(function () use ($request) {
|
|
$vip = new ExpertiseProduct();
|
|
$vip->fill($request->validated());
|
|
|
|
if ($vip->saveOrFail()) {
|
|
return redirect()->route('bo.vips.edit', $vip->id)
|
|
->with('success', __('crud.messages.has_been_created', [
|
|
'model' => Str::singular(trans_choice('models.classes.vips', 2))
|
|
]));
|
|
}
|
|
return redirect()->back()
|
|
->with('error', __('crud.messages.cannot_be_created', [
|
|
'model' => Str::singular(trans_choice('models.classes.vips', 2))
|
|
]));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param \App\Models\ExpertiseProduct $vip
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function edit(ExpertiseProduct $vip): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('bo.pages.vips.edit', ['vipModel' => $vip]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\Bo\ExpertiseProducts\UpdateExpertiseProductRequest $request
|
|
* @param \App\Models\ExpertiseProduct $vip
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function update(
|
|
UpdateExpertiseProductRequest $request,
|
|
ExpertiseProduct $vip
|
|
): \Illuminate\Http\RedirectResponse {
|
|
return DB::transaction(function () use ($request, $vip) {
|
|
$vip->fill($request->validated());
|
|
|
|
if ($vip->saveOrFail()) {
|
|
return redirect()->route('bo.vips.edit', $vip->id)
|
|
->with('success', __('crud.messages.has_been_updated', [
|
|
'model' => Str::singular(trans_choice('models.classes.vips', 2))
|
|
]));
|
|
}
|
|
return redirect()->route('bo.vips.edit', $vip->id)
|
|
->with('error', __('crud.messages.cannot_be_updated', [
|
|
'model' => Str::singular(trans_choice('models.classes.vips', 2))
|
|
]));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param \App\Models\ExpertiseProduct $vip
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function destroy(ExpertiseProduct $vip): \Illuminate\Http\RedirectResponse
|
|
{
|
|
if ($vip->deleteOrFail()) {
|
|
return redirect()->route('bo.vips.index')
|
|
->with('success', __('crud.messages.has_been_deleted', [
|
|
'model' => Str::singular(trans_choice('models.classes.vips', 2))
|
|
]));
|
|
}
|
|
return redirect()->back()
|
|
->with('error', __('crud.messages.cannot_be_deleted', [
|
|
'model' => Str::singular(trans_choice('models.classes.vips', 2))
|
|
]));
|
|
}
|
|
}
|