0
votes

My auth:: an attempt is not working. but my registration Form data will be stored in the User database and I also applied auth:: check(), it is also not working.

This is the controller

public function showLoginform(Request $request){

    $this->validate($request,[
        'email' => 'required',
        'password' => 'required',
    ]);

     $user_data = array(
         'email' => $request->get('email'),
         'password' => $request->get('password')
     );


 if(Auth::attempt($user_data)){
        //return \redirect::to("logged in successfuly");
        echo "yes match";
    } else{
        echo "not match";
       // return "oopps something wrong";
    } 

}

here is my model

class User extends Authenticatable { use Notifiable;

protected $table="users";


protected $fillable = [ 'name', 'email', 'password', 'phonenumber' , 'profession' , 'images' ];


protected $hidden = [
    'password', 'remember_token',
];
}
1
Did you hash your password? You should hash the passwords for using Auth::attemptЕвгений Одинец

1 Answers

0
votes

Use $request->input instead of $request->get

public function showLoginform(Request $request){

    $this->validate($request,[
        'email' => 'required',
        'password' => 'required',
    ]);

     $user_data = array(
         'email' => $request->input('email'),
         'password' => $request->input('password')
     );


 if(Auth::attempt($user_data)){
        //return \redirect::to("logged in successfuly");
        echo "yes match";
    } else{
        echo "not match";
       // return "oopps something wrong";
    } 

}