172 lines
5.8 KiB
PHP
172 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\FaqQuestions\StoreFaqQuestionRequest;
|
|
use App\Http\Requests\Bo\FaqQuestions\UpdateFaqQuestionRequest;
|
|
use App\Models\FaqQuestion;
|
|
use App\Models\FaqTheme;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
class FaqQuestionsController 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 $faqQuestionModels */
|
|
$faqQuestionModels = FaqQuestion::query();
|
|
|
|
/** @var string $search Search field */
|
|
$search = $request->search;
|
|
if ($search) {
|
|
$this->searchQuery(
|
|
$faqQuestionModels,
|
|
$search,
|
|
null,
|
|
'question',
|
|
'answer'
|
|
);
|
|
}
|
|
$searchFields = \sprintf(
|
|
'%s, %s ...',
|
|
Str::ucfirst(__('validation.custom.question')),
|
|
__('validation.attributes.answer'),
|
|
);
|
|
|
|
/** Sort columns with a query */
|
|
$this->sortQuery($faqQuestionModels);
|
|
|
|
/** Custom pagination */
|
|
$faqQuestionModels = $this->paginate($faqQuestionModels);
|
|
|
|
return view('back::pages.faq-questions.index', compact('faqQuestionModels', 'search', 'searchFields'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @param \App\Models\FaqQuestion $faqQuestion
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function create(FaqQuestion $faqQuestion): \Illuminate\Contracts\View\View
|
|
{
|
|
$faqThemeModels = FaqTheme::all();
|
|
return view('back::pages.faq-questions.create', [
|
|
'faqQuestionModel' => $faqQuestion,
|
|
'faqThemeModels' => $faqThemeModels
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\Bo\FaqQuestions\StoreFaqQuestionRequest $request
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function store(StoreFaqQuestionRequest $request): \Illuminate\Http\RedirectResponse
|
|
{
|
|
return DB::transaction(function () use ($request) {
|
|
$faqQuestion = new FaqQuestion();
|
|
$faqQuestion->fill($request->validated());
|
|
if ($faqQuestion->saveOrFail()) {
|
|
return redirect()
|
|
->route('bo.faq-questions.edit', $faqQuestion)
|
|
->with(
|
|
'success',
|
|
trans(
|
|
'crud.messages.has_been_created',
|
|
['model' => trans_choice('models.classes.faq-questions', 1)]
|
|
)
|
|
);
|
|
}
|
|
return redirect()
|
|
->back()
|
|
->with('error', trans(
|
|
'crud.messages.cannot_be_created',
|
|
['model' => trans_choice('models.classes.faq-questions', 1)]
|
|
));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param \App\Models\FaqQuestion $faqQuestion
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function edit(FaqQuestion $faqQuestion): \Illuminate\Contracts\View\View
|
|
{
|
|
$faqThemeModels = FaqTheme::all();
|
|
return view('back::pages.faq-questions.edit', [
|
|
'faqQuestionModel' => $faqQuestion,
|
|
'faqThemeModels' => $faqThemeModels
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\Bo\FaqQuestions\UpdateFaqQuestionRequest $request
|
|
* @param \App\Models\FaqQuestion $faqQuestion
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function update(
|
|
UpdateFaqQuestionRequest $request,
|
|
FaqQuestion $faqQuestion
|
|
): \Illuminate\Http\RedirectResponse {
|
|
return DB::transaction(function () use ($request, $faqQuestion) {
|
|
$faqQuestion->fill($request->validated());
|
|
if ($faqQuestion->saveOrFail()) {
|
|
return redirect()
|
|
->route(
|
|
'bo.faq-questions.edit',
|
|
$faqQuestion
|
|
)
|
|
->with('success', trans(
|
|
'crud.messages.has_been_updated',
|
|
['model' => trans_choice('models.classes.faq-questions', 1)]
|
|
));
|
|
}
|
|
return redirect()
|
|
->back()
|
|
->with('error', trans(
|
|
'crud.messages.cannot_be_updated',
|
|
['model' => trans_choice('models.classes.faq-questions', 1)]
|
|
));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param \App\Models\FaqQuestion $faqQuestion
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function destroy(FaqQuestion $faqQuestion): \Illuminate\Http\RedirectResponse
|
|
{
|
|
return DB::transaction(function () use ($faqQuestion) {
|
|
if ($faqQuestion->deleteOrFail()) {
|
|
return redirect()
|
|
->route('bo.faq-questions.index')
|
|
->with('success', __(
|
|
'crud.messages.has_been_deleted',
|
|
['model' => trans_choice('models.classes.faq-questions', 1)]
|
|
));
|
|
}
|
|
return redirect()
|
|
->back()
|
|
->with('error', __(
|
|
':crud.messages.cannot_be_deleted',
|
|
['model' => trans_choice('models.classes.faq-questions', 1)]
|
|
));
|
|
});
|
|
}
|
|
}
|