158 lines
5.4 KiB
PHP
158 lines
5.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\Informations\StoreInformationRequest;
|
|
use App\Http\Requests\Bo\Informations\UpdateInformationRequest;
|
|
use App\Models\Information;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
class InformationController 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 $informationModels */
|
|
$informationModels = Information::query();
|
|
|
|
/** @var string $search Search field */
|
|
$search = $request->search;
|
|
if ($search) {
|
|
$this->searchQuery(
|
|
$informationModels,
|
|
$search,
|
|
null,
|
|
'title',
|
|
'message'
|
|
);
|
|
}
|
|
$searchFields = trans('Titre, message');
|
|
|
|
/** Sort columns with a query */
|
|
$this->sortQuery($informationModels);
|
|
|
|
/** Custom pagination */
|
|
$informationModels = $this->customPaginate($informationModels, $request->pagination);
|
|
|
|
return view('bo.pages.informations.index', compact('informationModels', 'search', 'searchFields'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @param \App\Models\Information $information
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function create(Information $information): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('bo.pages.informations.create', [
|
|
'informationModel' => $information
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\Bo\Informations\StoreInformationRequest $request
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function store(StoreInformationRequest $request): \Illuminate\Http\RedirectResponse
|
|
{
|
|
return DB::transaction(function () use ($request) {
|
|
$information = new Information();
|
|
$information->fill($request->validated());
|
|
|
|
if ($information->saveOrFail()) {
|
|
return redirect()
|
|
->route('bo.informations.edit', $information)
|
|
->with('success', trans(
|
|
'crud.messages.has_been_created',
|
|
['model' => Str::singular(trans('models.classes.informations'))]
|
|
));
|
|
}
|
|
return redirect()
|
|
->back()
|
|
->with('error', trans(
|
|
'crud.messages.cannot_be_created',
|
|
['model' => Str::singular(trans('models.classes.informations'))]
|
|
));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param \App\Models\Information $information
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function edit(Information $information): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('bo.pages.informations.edit', [
|
|
'informationModel' => $information,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\Bo\Informations\UpdateInformationRequest $request
|
|
* @param \App\Models\Information $information
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
* @ignore phpcs:disable Generic.Files.LineLength.TooLong
|
|
*/
|
|
public function update(UpdateInformationRequest $request, Information $information): \Illuminate\Http\RedirectResponse
|
|
{
|
|
// phpcs:enable
|
|
return DB::transaction(function () use ($request, $information) {
|
|
$information->fill($request->validated());
|
|
if ($information->saveOrFail()) {
|
|
return redirect()
|
|
->route('bo.informations.edit', $information)
|
|
->with('success', trans(
|
|
'crud.messages.has_been_updated',
|
|
['model' => Str::singular(trans('models.classes.informations'))]
|
|
));
|
|
} //end if
|
|
return redirect()
|
|
->back()
|
|
->with('error', trans(
|
|
'crud.messages.cannot_be_updated',
|
|
['model' => Str::singular(trans('models.classes.informations'))]
|
|
));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param \App\Models\Information $information
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function destroy(Information $information): \Illuminate\Http\RedirectResponse
|
|
{
|
|
return DB::transaction(function () use ($information) {
|
|
if ($information->deleteOrFail()) {
|
|
return redirect()
|
|
->route('bo.informations.index')
|
|
->with('success', trans(
|
|
'crud.messages.has_been_deleted',
|
|
['model' => Str::singular(trans('models.classes.informations'))]
|
|
));
|
|
}
|
|
return redirect()
|
|
->back()
|
|
->with('error', trans(
|
|
':crud.messages.cannot_be_deleted',
|
|
['model' => Str::singular(trans('models.classes.informations'))]
|
|
));
|
|
});
|
|
}
|
|
}
|