<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Http\Request;

class ForgotPasswordController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Password Reset Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password reset emails and
    | includes a trait which assists in sending these notifications from
    | your application to your users. Feel free to explore this trait.
    |
    */

    use SendsPasswordResetEmails;

    public function sendResetLinkEmail(Request $request)
    {
        $user = User::where([
            ['email', $request->email],
            ['active', 1]
        ])->first();

        if($user) {
            $this->broker()->sendResetLink(
                $request->only('email')
            );

            return back()->with('status', 'Te hemos enviado un mensaje a tu dirección de correo');
        } else {
            return back()->withInput()->with('status', 'No existe usuario');
        }
    }
}
