<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use App\Mail\SubscriberMail;

class SubscriberController extends Controller
{
    public function sendMailToSubscriber() {
        if (Auth::check() && Auth::user()->status == 1) {
            $user = Auth::user();
            Mail::to($user->email)->send(new SubscriberMail($user));
            $user->update([
                'subscribe' => 1,
            ]);
            return response()->json([
                'message' => 'Thank for your subscribing!!!',
                'status' => 200,
                'data' => $user
            ]);
        }
        return redirect()->route('login');
    }
}
