2021-02-15 17:44:45 +01:00
|
|
|
<?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) {
|
2021-04-28 13:57:12 +02:00
|
|
|
$question->positive_vote = intval(($question->positive_vote ?? 0) + 1);
|
2021-02-15 17:44:45 +01:00
|
|
|
} else {
|
2021-04-28 13:57:12 +02:00
|
|
|
$question->negative_vote = intval(($question->negative_vote ?? 0) + 1);
|
2021-02-15 17:44:45 +01:00
|
|
|
}
|
2021-04-28 13:57:12 +02:00
|
|
|
$question->saveOrFail();
|
2021-02-15 17:44:45 +01:00
|
|
|
}
|
|
|
|
|
return response()->json();
|
|
|
|
|
}
|
|
|
|
|
}
|