182 lines
6.4 KiB
PHP
182 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\ApproachSlides\StoreApproachSlideRequest;
|
|
use App\Http\Requests\Bo\ApproachSlides\UpdateApproachSlideRequest;
|
|
use App\Models\ApproachSlide;
|
|
use App\Traits\Controllers\ChangesModelOrder;
|
|
use App\Traits\Controllers\UpdateModelPublished;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
class ApproachSlideController extends Controller
|
|
{
|
|
use ChangesModelOrder;
|
|
use UpdateModelPublished;
|
|
|
|
/**
|
|
* Create the controller instance.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->authorizeResource(ApproachSlide::class);
|
|
}
|
|
|
|
/**
|
|
* 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 $approachSlideModels */
|
|
$approachSlideModels = ApproachSlide::query();
|
|
|
|
/** @var string $search Search field */
|
|
$search = $request->search;
|
|
if ($search) {
|
|
$this->searchQuery(
|
|
$approachSlideModels,
|
|
$search,
|
|
null,
|
|
'title',
|
|
'text',
|
|
);
|
|
}
|
|
$searchFields = \implode(', ', [
|
|
trans('validation.attributes.title'),
|
|
trans('validation.attributes.text'),
|
|
]);
|
|
|
|
/** Sort columns with a query */
|
|
$this->sortQuery($approachSlideModels);
|
|
|
|
/** Custom pagination */
|
|
$approachSlideModels = $this->paginate($approachSlideModels);
|
|
|
|
return view('bo.pages.approach_slides.index', compact('approachSlideModels', 'search', 'searchFields'));
|
|
}
|
|
|
|
/**
|
|
* Show the specified resource.
|
|
*
|
|
* @param \App\Models\ApproachSlide $approachSlide
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function show(ApproachSlide $approachSlide): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('bo.pages.approach_slides.show', ['approachSlideModel' => $approachSlide]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @param \App\Models\ApproachSlide $approachSlide
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function create(ApproachSlide $approachSlide): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('bo.pages.approach_slides.create', ['approachSlideModel' => $approachSlide]);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\Bo\ApproachSlides\StoreApproachSlideRequest $request
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function store(StoreApproachSlideRequest $request): \Illuminate\Http\RedirectResponse
|
|
{
|
|
return DB::transaction(function () use ($request) {
|
|
$approachSlide = new ApproachSlide();
|
|
$approachSlide->fill($request->validated());
|
|
|
|
if ($approachSlide->saveOrFail()) {
|
|
return redirect()->route('bo.approach_slides.edit', $approachSlide)
|
|
->with('success', trans('crud.messages.has_been_created', [
|
|
'model' => Str::ucfirst(trans('models.classes.approach_slide'))
|
|
]));
|
|
}
|
|
return redirect()->back()
|
|
->with('error', trans('crud.messages.cannot_be_created', [
|
|
'model' => Str::ucfirst(trans('models.classes.approach_slide'))
|
|
]));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param \App\Models\ApproachSlide $approachSlide
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function edit(ApproachSlide $approachSlide): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('bo.pages.approach_slides.edit', ['approachSlideModel' => $approachSlide]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\Bo\ApproachSlides\UpdateApproachSlideRequest $request
|
|
* @param \App\Models\ApproachSlide $approachSlide
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function update(
|
|
UpdateApproachSlideRequest $request,
|
|
ApproachSlide $approachSlide
|
|
): \Illuminate\Http\RedirectResponse {
|
|
return DB::transaction(function () use ($request, $approachSlide) {
|
|
$approachSlide->fill($request->validated());
|
|
|
|
if ($approachSlide->saveOrFail()) {
|
|
return redirect()->route('bo.approach_slides.edit', $approachSlide)
|
|
->with('success', trans('crud.messages.has_been_updated', [
|
|
'model' => Str::ucfirst(trans('models.classes.approach_slide'))
|
|
]));
|
|
}
|
|
return redirect()->route('bo.approach_slides.edit', $approachSlide)
|
|
->with('error', trans('crud.messages.cannot_be_updated', [
|
|
'model' => Str::ucfirst(trans('models.classes.approach_slide'))
|
|
]));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param \App\Models\ApproachSlide $approachSlide
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function destroy(ApproachSlide $approachSlide): \Illuminate\Http\RedirectResponse
|
|
{
|
|
/** @var array<string,string> */
|
|
$previousQueries = [];
|
|
\parse_str(\parse_url(url()->previous(), \PHP_URL_QUERY), $previousQueries);
|
|
if ($approachSlide->deleteOrFail()) {
|
|
return redirect()->route('bo.approach_slides.index', $previousQueries)
|
|
->with('success', trans('crud.messages.has_been_deleted', [
|
|
'model' => Str::ucfirst(trans('models.classes.approach_slide'))
|
|
]));
|
|
}
|
|
return redirect()->back()
|
|
->with('error', trans('crud.messages.cannot_be_deleted', [
|
|
'model' => Str::ucfirst(trans('models.classes.approach_slide'))
|
|
]));
|
|
}
|
|
|
|
/**
|
|
* Duplicate the specified resource.
|
|
*
|
|
* @param \App\Models\ApproachSlide $approachSlide
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function duplicate(ApproachSlide $approachSlide): \Illuminate\Contracts\View\View
|
|
{
|
|
return $this->create($approachSlide->replicate());
|
|
}
|
|
}
|