<?php

namespace App\Http\Controllers;

use App\Mail\Suscripcion;
use App\Models\Email;
use App\Models\Welcome;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;

class EmailController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        $email = new Email();
        $email->email = $request->email;
        $email->emailencryption = md5($request->email);
        $email->save();

        $mail = Welcome::find(1);

        Mail::to($request->email)->send(new Suscripcion($email->emailencryption, $mail));
        
        return redirect()->route('gracias');
       
    }

    /**
     * Display the specified resource.
     */
    public function show(Email $email)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(Email $email)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, Email $email)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(Email $email)
    {
        //
    }
}
