46 lines
1.0 KiB
PHP
46 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Client;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\FAQ;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
|
|
class FaqController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$faqs = FAQ::all();
|
|
$faqResponse = $faqs->map(function ($item) {
|
|
return [
|
|
'question' => $item->question,
|
|
'answer' => $item->answer,
|
|
];
|
|
});
|
|
return Inertia::render("dashboard/faq/index", ['faq' => $faqResponse]);
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
return Inertia::render("dashboard/faq/add");
|
|
}
|
|
|
|
public function addFaq(Request $request)
|
|
{
|
|
$validated = $request->validate([
|
|
"question" => "required|string",
|
|
"answer" => "required|string"
|
|
]);
|
|
|
|
$faq = FAQ::create($validated);
|
|
|
|
$faqResponse = [
|
|
"question" => $faq->question,
|
|
"answer" => $faq->answer,
|
|
];
|
|
|
|
return to_route("dashboard.faq.show", ['faq' => $faqResponse]);
|
|
}
|
|
}
|