Store contact messages in DB and seed real bilingual blog content
Deploy Backend / deploy (push) Successful in 2m40s

Contact form messages were sent via mailto and the site has no mail
service, so visitors saw a placeholder caveat instead of a working
channel. Add a contact_messages table, a public throttled POST endpoint,
and admin list/mark/delete endpoints, then wire them into the panel.

Replace the faker-generated blog demonstration content with real
English and Persian SEO-oriented articles via RealBlogContentSeeder
(deterministic, bilingual posts with per-language categories and tags,
and cross-linked related posts).
This commit is contained in:
Parsa Aghayi committed 2026-10-02 05:41:05 -04:00
1 parent 16057c06b9
commit d4f41b9c2e
8 files changed
+930

No files matched your search

@@ -0,0 +1,70 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\ContactMessage;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
/**
* @OA\Tag(name="Contact", description="Contact form submissions")
*/
class ContactMessageController extends Controller
{
/**
* Public contact form submission.
*
* The site has no mail service of its own; messages are stored in the
* database and read from the admin panel instead of being emailed.
*/
public function store(Request $request): JsonResponse
{
$validated = $request->validate([
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', 'max:255'],
'message' => ['required', 'string', 'max:5000'],
]);
$message = ContactMessage::create([
'name' => $validated['name'],
'email' => $validated['email'],
'message' => $validated['message'],
]);
return response()->json(['message' => 'پیام شما با موفقیت ثبت شد.'], 201);
}
/**
* List every contact message, newest first.\
*/
public function index(): JsonResponse
{
$messages = ContactMessage::query()->orderByDesc('id')->get();
return response()->json(['data' => $messages]);
}
/**
* Mark a message as read (or unread).
*/
public function markRead(Request $request, int $id): JsonResponse
{
$message = ContactMessage::findOrFail($id);
$message->read_at = $request->boolean('read') ? now() : null;
$message->save();
return response()->json(['data' => $message]);
}
/**
* Delete a message.
*/
public function destroy(int $id): JsonResponse
{
ContactMessage::findOrFail($id)->delete();
return response()->json(null, 200);
}
}