feat: FAQ controller made
This commit is contained in:
45
app/Http/Controllers/Client/FaqController.php
Normal file
45
app/Http/Controllers/Client/FaqController.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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]);
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,15 @@ class HomeController extends Controller
|
||||
|
||||
public function faq()
|
||||
{
|
||||
return Inertia::render('faq');
|
||||
$faq = FAQ::all();
|
||||
$faqResponse = $faq->map(function ($item) {
|
||||
return [
|
||||
"id" => $item->id,
|
||||
"question" => $item->question,
|
||||
"answer" => $item->answer,
|
||||
];
|
||||
});
|
||||
return Inertia::render('faq', ['faq' => $faqResponse]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
14
app/Models/FAQ.php
Normal file
14
app/Models/FAQ.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class FAQ extends Model
|
||||
{
|
||||
protected $table = "faqs";
|
||||
protected $fillable = [
|
||||
"question",
|
||||
"answer"
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user