samedi 5 décembre 2015

Unable to login using Laravel 5.1

I am trying to create a login in Laravel 5.1 and I've not been able to login using this snippet. This is to allow a user to login using either username and password.

Controller class:

 public function login(Request $request)
            {
                $field = filter_var($request->input('login'), FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
                $request->merge([$field => $request->input('login')]);

                if (Auth::attempt($request->only($field, 'password')))
                {
                    return redirect()->route('home')->with('message', 'You have successfully logged in');
                }

                return redirect('login')
                    ->with('message', 'Your username/password combination is not correct')
                    ->withInput();
            }

This is the reuest rules:

public function rules()
    {
        return [
            'login'=>'required',
            'password'=>'required'
        ];
    }

What exactly is wrong? Kindly help me out. I appreciate.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire