<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Subscriber;

class NewsletterController extends Controller
{
   public function subscribe(Request $request)
{
    $request->validate([
        'email' => 'required|email|unique:tbl_user,email',
    ], [
        'email.unique' => 'This email is already registered!'
    ]);

    Subscriber::create([
        'email' => $request->email,
        'role' => 'subscriber',
        'status' => 1,
    ]);

    return response()->json([
        'status' => 'success',
        'message' => 'Email successfully registered!'
    ]);
}

}
