133 lines
3.8 KiB
PHP
133 lines
3.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\Http\Response
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
/** @var \Illuminate\Database\Eloquent\Builder $vips */
|
|
$vips = ExpertiseProduct::query();
|
|
|
|
if ($request->search) {
|
|
$this->searchQuery(
|
|
$vips,
|
|
$request->search,
|
|
null,
|
|
'label',
|
|
'title'
|
|
);
|
|
}
|
|
|
|
$this->sortQuery($vips);
|
|
$searchFields = trans('Libellé, Titre');
|
|
|
|
$vips = $vips->paginate(10);
|
|
|
|
return view('bo.pages.vips.index', compact('vips', 'searchFields'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('bo.pages.vips.create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\Bo\ExpertiseProducts\StoreExpertiseProductRequest $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(StoreExpertiseProductRequest $request)
|
|
{
|
|
return DB::transaction(function () use ($request) {
|
|
$vip = new ExpertiseProduct();
|
|
$vip->fill($request->validated());
|
|
|
|
if ($vip->saveOrFail()) {
|
|
return redirect()
|
|
->route('bo.vips.edit', $vip)
|
|
->with('success', trans(
|
|
':model a été créé',
|
|
['model' => Str::singular(trans('models.classes.vips'))]
|
|
));
|
|
}
|
|
return back();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param \App\Models\ExpertiseProduct $vip
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit(ExpertiseProduct $vip)
|
|
{
|
|
return view('bo.pages.vips.edit', [
|
|
'vip' => $vip
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\Bo\ExpertiseProduct\UpdateExpertiseProductRequest $request
|
|
* @param \App\Models\ExpertiseProduct $vip
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(UpdateExpertiseProductRequest $request, ExpertiseProduct $vip)
|
|
{
|
|
return DB::transaction(function () use ($request, $vip) {
|
|
$vip->fill($request->validated());
|
|
|
|
if ($vip->saveOrFail()) {
|
|
return redirect()
|
|
->route('bo.vips.edit', $vip)
|
|
->with('success', trans(
|
|
':model a été mis à jour',
|
|
['model' => Str::singular(trans('models.classes.vips'))]
|
|
));
|
|
}
|
|
return back();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param \App\Models\ExpertiseProduct $vip
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(ExpertiseProduct $vip)
|
|
{
|
|
if ($vip->deleteOrFail()) {
|
|
return redirect()
|
|
->route('bo.vips.index')
|
|
->with('warning', trans(
|
|
':model a bien été supprimé',
|
|
['model' => Str::singular(trans('models.classes.vips'))]
|
|
));
|
|
}
|
|
return back();
|
|
}
|
|
}
|