<?php

namespace App\Http\Controllers\Web\Marketing;

use App\Http\Controllers\Controller;
use App\Models\CMS\Marketing\NewsletterUser;
use Illuminate\Http\Request;

class NewsletterSubscriptionController extends Controller
{
    public function store(Request $request)
    {
        $this->validate($request, [
            'email' => ['required', 'string', 'email', 'unique:newsletter_users'],
        ]);

        NewsletterUser::create(['email' => $request->email]);

        return $request->ajax() ? ['success' => true] : back()->with('message', 'Successfully subscribed');
    }
}
