2024-08-09 13:44:11 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Http\Requests\Bo\Testimonials\StoreTestimonialRequest;
|
|
|
|
|
use App\Http\Requests\Bo\Testimonials\UpdateTestimonialRequest;
|
|
|
|
|
use App\Models\Meat;
|
|
|
|
|
use App\Models\Testimonial;
|
|
|
|
|
use App\Traits\Controllers\UpdateModelPublished;
|
2026-09-25 16:25:31 +02:00
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
2024-08-09 13:44:11 +02:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
2024-10-09 14:35:27 +02:00
|
|
|
use Illuminate\Support\Str;
|
2024-08-09 13:44:11 +02:00
|
|
|
|
|
|
|
|
class TestimonialController extends Controller
|
|
|
|
|
{
|
|
|
|
|
use UpdateModelPublished;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create the controller instance.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->authorizeResource(Testimonial::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*/
|
2026-09-25 16:25:31 +02:00
|
|
|
public function index(Request $request): View
|
2024-08-09 13:44:11 +02:00
|
|
|
{
|
|
|
|
|
/** @var \Illuminate\Database\Eloquent\Builder $testimonialModels */
|
|
|
|
|
$testimonialModels = Testimonial::query();
|
|
|
|
|
|
|
|
|
|
/** @var string $search Search field */
|
|
|
|
|
$search = $request->search;
|
|
|
|
|
if ($search) {
|
|
|
|
|
$this->searchQuery(
|
|
|
|
|
$testimonialModels,
|
|
|
|
|
$search,
|
|
|
|
|
null,
|
|
|
|
|
'catchline',
|
|
|
|
|
'content',
|
|
|
|
|
'identity',
|
|
|
|
|
'job',
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-10-09 14:35:27 +02:00
|
|
|
$searchFields = Str::ucFirst(\implode(', ', [
|
2024-08-09 13:44:11 +02:00
|
|
|
trans_choice('validation.custom.catchline', 1),
|
|
|
|
|
trans('validation.attributes.content'),
|
|
|
|
|
trans('validation.custom.testimonial_identity'),
|
|
|
|
|
trans('validation.custom.job'),
|
2024-10-09 14:35:27 +02:00
|
|
|
]));
|
2024-08-09 13:44:11 +02:00
|
|
|
|
|
|
|
|
/** Sort columns with a query */
|
|
|
|
|
$this->sortQuery($testimonialModels);
|
|
|
|
|
|
|
|
|
|
/** Custom pagination */
|
|
|
|
|
$testimonialModels = $this->paginate($testimonialModels);
|
|
|
|
|
|
|
|
|
|
return view('bo.pages.testimonials.index', compact('testimonialModels', 'search', 'searchFields'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show a specific resource.
|
|
|
|
|
*/
|
2026-09-25 16:25:31 +02:00
|
|
|
public function show(Testimonial $testimonial): View
|
2024-08-09 13:44:11 +02:00
|
|
|
{
|
|
|
|
|
return view('bo.pages.testimonials.show', ['testimonialModel' => $testimonial]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
|
*/
|
2026-09-25 16:25:31 +02:00
|
|
|
public function create(Testimonial $testimonial): View
|
2024-08-09 13:44:11 +02:00
|
|
|
{
|
|
|
|
|
$meatModels = Meat::query()->orderBy('order')->get();
|
|
|
|
|
|
|
|
|
|
return view('bo.pages.testimonials.create', [
|
|
|
|
|
'testimonialModel' => $testimonial,
|
2024-10-09 14:35:27 +02:00
|
|
|
'meatModels' => $meatModels,
|
2024-08-09 13:44:11 +02:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
|
*/
|
2026-09-25 16:25:31 +02:00
|
|
|
public function store(StoreTestimonialRequest $request): RedirectResponse
|
2024-08-09 13:44:11 +02:00
|
|
|
{
|
|
|
|
|
return DB::transaction(function () use ($request) {
|
|
|
|
|
$testimonial = new Testimonial();
|
|
|
|
|
$testimonial->fill($request->validated());
|
|
|
|
|
|
|
|
|
|
if ($testimonial->saveOrFail()) {
|
|
|
|
|
return redirect()->route('bo.testimonials.edit', $testimonial)
|
2024-09-06 10:38:10 +02:00
|
|
|
->with('success', trans('crud.messages.has_been_created', [
|
2026-09-25 16:25:31 +02:00
|
|
|
'model' => Str::ucFirst(trans('models.classes.testimonial')),
|
2024-08-09 13:44:11 +02:00
|
|
|
]));
|
|
|
|
|
}
|
2026-09-25 16:25:31 +02:00
|
|
|
|
2024-08-09 13:44:11 +02:00
|
|
|
return redirect()->back()
|
2024-09-06 10:38:10 +02:00
|
|
|
->with('error', trans('crud.messages.cannot_be_created', [
|
2026-09-25 16:25:31 +02:00
|
|
|
'model' => Str::ucFirst(trans('models.classes.testimonial')),
|
2024-08-09 13:44:11 +02:00
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
|
*/
|
2026-09-25 16:25:31 +02:00
|
|
|
public function edit(Testimonial $testimonial): View
|
2024-08-09 13:44:11 +02:00
|
|
|
{
|
|
|
|
|
$meatModels = Meat::query()->orderBy('order')->get();
|
|
|
|
|
|
|
|
|
|
return view('bo.pages.testimonials.edit', [
|
|
|
|
|
'testimonialModel' => $testimonial,
|
2024-10-09 14:35:27 +02:00
|
|
|
'meatModels' => $meatModels,
|
2024-08-09 13:44:11 +02:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
|
*/
|
|
|
|
|
public function update(
|
|
|
|
|
UpdateTestimonialRequest $request,
|
|
|
|
|
Testimonial $testimonial
|
2026-09-25 16:25:31 +02:00
|
|
|
): RedirectResponse {
|
2024-08-09 13:44:11 +02:00
|
|
|
return DB::transaction(function () use ($request, $testimonial) {
|
|
|
|
|
$testimonial->fill($request->validated());
|
|
|
|
|
|
|
|
|
|
if ($testimonial->saveOrFail()) {
|
|
|
|
|
return redirect()->route('bo.testimonials.edit', $testimonial)
|
2024-09-06 10:38:10 +02:00
|
|
|
->with('success', trans('crud.messages.has_been_updated', [
|
2026-09-25 16:25:31 +02:00
|
|
|
'model' => Str::ucFirst(trans('models.classes.testimonial')),
|
2024-08-09 13:44:11 +02:00
|
|
|
]));
|
|
|
|
|
}
|
2026-09-25 16:25:31 +02:00
|
|
|
|
2024-08-09 13:44:11 +02:00
|
|
|
return redirect()->route('bo.testimonials.edit', $testimonial)
|
2024-09-06 10:38:10 +02:00
|
|
|
->with('error', trans('crud.messages.cannot_be_updated', [
|
2026-09-25 16:25:31 +02:00
|
|
|
'model' => Str::ucFirst(trans('models.classes.testimonial')),
|
2024-08-09 13:44:11 +02:00
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
|
*/
|
2026-09-25 16:25:31 +02:00
|
|
|
public function destroy(Testimonial $testimonial): RedirectResponse
|
2024-08-09 13:44:11 +02:00
|
|
|
{
|
|
|
|
|
/** @var array<string,string> */
|
|
|
|
|
$previousQueries = [];
|
|
|
|
|
\parse_str(\parse_url(url()->previous(), \PHP_URL_QUERY), $previousQueries);
|
|
|
|
|
if ($testimonial->deleteOrFail()) {
|
|
|
|
|
return redirect()->route('bo.testimonials.index', $previousQueries)
|
2024-09-06 10:38:10 +02:00
|
|
|
->with('success', trans('crud.messages.has_been_deleted', [
|
2026-09-25 16:25:31 +02:00
|
|
|
'model' => Str::ucFirst(trans('models.classes.testimonial')),
|
2024-08-09 13:44:11 +02:00
|
|
|
]));
|
|
|
|
|
}
|
2026-09-25 16:25:31 +02:00
|
|
|
|
2024-08-09 13:44:11 +02:00
|
|
|
return redirect()->back()
|
2024-09-06 10:38:10 +02:00
|
|
|
->with('error', trans('crud.messages.cannot_be_deleted', [
|
2026-09-25 16:25:31 +02:00
|
|
|
'model' => Str::ucFirst(trans('models.classes.testimonial')),
|
2024-08-09 13:44:11 +02:00
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Duplicate the specified resource.
|
|
|
|
|
*/
|
2026-09-25 16:25:31 +02:00
|
|
|
public function duplicate(Testimonial $testimonial): View
|
2024-08-09 13:44:11 +02:00
|
|
|
{
|
|
|
|
|
return $this->create($testimonial->replicate());
|
|
|
|
|
}
|
|
|
|
|
}
|