B
B
blackVirus2022-03-12 12:06:56
Laravel
blackVirus, 2022-03-12 12:06:56

Login through laravel does not work and I can't find the reason)?

Controller code

public function login(Request $request){
        if (Auth::check()){
            return redirect(route('Account'));
        }

        $formFields = $request->only(['Login', 'Password']);

//        dd($formFields);

        if(Auth::attempt($formFields)){
            return redirect()->intended(route('Account'));
        }

        return redirect(route('LoginPage'))->withErrors([
            'Login' => 'Произошла ошибка при входе!',
        ]);
    }


It doesn't throw any errors, it just skips the condition as if it were an empty value in the array and executes the following code
return redirect(route('LoginPage'))->withErrors([
            'Login' => 'Произошла ошибка при входе!',
        ]);


User model code
public function setPasswordAttribute($password){
        $this->attributes['Password'] = Hash::make($password);
    }


Page Code
<div class="FormAuth">
            <p class="p7">Вход</p>
            <form class="formReg" action="{{route('login')}}" method="POST">
                @csrf
                <input type="text" name="Login" value="" placeholder="Введите логин" class="input">
                @error('Login')
                <div><p class="p6">{{$message}}</p></div>
                @enderror
                <input type="password" name="Password" value="" placeholder="Введите пароль" class="input">
                @error('Password')
                <div><p>{{$message}}</p></div>
                @enderror
                <button type="submit" class="btn-reg log-btn" value="#"><p class="p9">Войти</p></button>
            </form>
            <a href="{{route('Authentication')}}" class="cnp-auth"><p class="p9 pCorrected">Нажмите сюда если хотите зарегистрироваться!</p></a>
        </div>


Through dd , the norm data from the form is sent, and then what doesn’t work
622c6288667bc213021022.png

?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
blackVirus, 2022-03-13
@blackVirus

Krch problem with the names in the database you can not write Password instead of password, I found that supposedly this function replaces the standard name

public function  getAuthPassword()
    {
        return $this->attributes['Название твоего столбца в бд'];
        
        // или

        return $this->Название твоего столбца в бд;
    }

But it didn’t have any effect for me.
I also tried to dig into the file along the path vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php
622e096ec984e398059467.png
Substituting my name for the place password and this also didn’t work, most likely my hands from w and I just reconciled and changed the name of the column to password in the database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question