35 lines
1,022 B
PHP
35 lines
1,022 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\UpdateStatisfationStatRequest;
|
|
use App\Models\FaqQuestions;
|
|
use App\Models\FaqThemes;
|
|
use Illuminate\Http\Request;
|
|
|
|
class FaqController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
return view('front.faq.index', [
|
|
'themes' => FaqThemes::with('questions')->get()
|
|
]);
|
|
}
|
|
|
|
public function updateSatisfactionStat(UpdateStatisfationStatRequest $request, FaqQuestions $question)
|
|
{
|
|
$opinion = (bool)$request->opinion;
|
|
$sessionKey = sprintf('faq.questions.%d', $question->id);
|
|
if (!session()->has($sessionKey)) {
|
|
session()->put($sessionKey, true);
|
|
session()->save();
|
|
if ($opinion) {
|
|
$question->positive_vote = $question->positive_vote ?? 0 + 1;
|
|
} else {
|
|
$question->negative_vote = $question->negative_vote ?? 0 + 1;
|
|
}
|
|
$question->save();
|
|
}
|
|
return response()->json();
|
|
}
|
|
}
|