111 lines
3.4 KiB
PHP
111 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\Faqs\StoreFaqRequest;
|
|
use App\Http\Requests\Bo\Faqs\UpdateFaqRequest;
|
|
use App\Models\Faq;
|
|
use App\Services\DataTableService;
|
|
use App\Traits\Controllers\ChangesModelOrder;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
class FaqsController extends Controller
|
|
{
|
|
use ChangesModelOrder;
|
|
|
|
public function index(DataTableService $dataTable): View
|
|
{
|
|
$this->authorize('viewAny', Faq::class);
|
|
|
|
$query = Faq::query();
|
|
|
|
$dataTable->sortQuery(Faq::class, $query);
|
|
|
|
$faqs = $dataTable->paginateQuery($query);
|
|
|
|
return view('bo.faqs.index', compact('faqs'));
|
|
}
|
|
|
|
public function create(): View
|
|
{
|
|
$this->authorize('create', Faq::class);
|
|
|
|
return view('bo.faqs.create');
|
|
}
|
|
|
|
public function store(StoreFaqRequest $request): RedirectResponse
|
|
{
|
|
$this->authorize('create', Faq::class);
|
|
|
|
return DB::transaction(function () use ($request) {
|
|
$faq = new Faq();
|
|
$faq->fill($request->only(
|
|
$faq->getFillable()
|
|
));
|
|
if ($faq->saveOrFail()) {
|
|
return to_route('bo.faqs.edit', $faq)
|
|
->with('success', trans('crud.messages.has_been_created', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.faqs', 1)),
|
|
]));
|
|
}
|
|
|
|
return to_route('bo.faqs.create')
|
|
->with('error', trans('crud.messages.cannot_be_created', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.faqs', 1)),
|
|
]));
|
|
});
|
|
}
|
|
|
|
public function edit(Faq $faq): View
|
|
{
|
|
$this->authorize('update', $faq);
|
|
|
|
return view('bo.faqs.edit', compact('faq'));
|
|
}
|
|
|
|
public function update(UpdateFaqRequest $request, Faq $faq): RedirectResponse
|
|
{
|
|
$this->authorize('update', $faq);
|
|
|
|
return DB::transaction(function () use ($request, $faq) {
|
|
$faq->fill($request->only(
|
|
$faq->getFillable()
|
|
));
|
|
|
|
if ($faq->saveOrFail()) {
|
|
return to_route('bo.faqs.edit', $faq)
|
|
->with('success', trans('crud.messages.has_been_updated', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.faqs', 1)),
|
|
]));
|
|
}
|
|
|
|
return to_route('bo.faqs.edit', $faq)
|
|
->with('error', trans('crud.messages.cannot_be_updated', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.faqs', 1)),
|
|
]));
|
|
});
|
|
}
|
|
|
|
public function destroy(Faq $faq): RedirectResponse
|
|
{
|
|
$this->authorize('delete', $faq);
|
|
|
|
return DB::transaction(function () use ($faq) {
|
|
if ($faq->deleteOrFail()) {
|
|
return to_route('bo.faqs.index')
|
|
->with('warning', trans('crud.messages.has_been_deleted', ['model' => Str::ucfirst(trans_choice('models.classes.faqs', \INF))]));
|
|
}
|
|
|
|
return to_route('bo.faqs.edit', $faq)
|
|
->with('error', trans('crud.messages.cannot_be_deleted', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.faqs', 1)),
|
|
]));
|
|
});
|
|
}
|
|
}
|