<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Mail\ShareWithFriendMail;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
class ShareWithFriendController extends Controller
{
    public function sendMailToShareWithFriend(Request $request) {
        if (Auth::check() && Auth::user()->status == 1) {
            $user = Auth::user();
            $email = $request->email;
            Mail::to($email)->send(new ShareWithFriendMail($user));
            return response()->json([
                'message' => 'Thank you for sharing!!!',
                'status' => 200,
                'data' => $user
            ]);
        }
        return redirect()->route('login');
    }
}
