Login and login to Laravel 5.7

Asked

Viewed 2,219 times

0

I’m developing a project in Laravel, but I’m having a hard time understanding how user login and authentication works to redirect to Dashboard.

I have a table in the database called "user", which contains the following columns: id, name, user, password and email.

The authentication has to be done through e-mail and password, which are already registered. The password is hashed MD5, being created through Phpmyadmin.

Admincontroller was created. Below:

public function index(Request $request){

    $credentials = $request->only('email', 'senha');

    if (Auth::attempt($credentials)) {
        // Authentication passed...
        return redirect()->intended('dashboard');
    } else {
        return redirect()->intended('index');
    }

    }

Model Admin was also created. Below:

class Admin extends Model
{
    protected $fillable = ['nome', 'usuario', 'senha', 'email', 'admin'];
    protected $guarded = ['id','created_at', 'update_at'];
    protected $table = 'usuario';
    public $timestamps = false;
}

However, when I type the user and password from the Login screen, the following error occurs:

Method App Http Controllers Dashboardcontroller::store does not exist.

My Login view looks like this:

    <div class="account-pages mt-5 mb-5">
        <div class="container">
            <div class="row justify-content-center">
                <div class="col-lg-5">
                    <div class="card">

                        <!-- Logo -->
                        <div class="card-header pt-4 pb-4 text-center bg-primary">
                            <a href="index.html">
                                <span><img src="site/img/logo-login.png" alt=""></span>
                            </a>
                        </div>

                        <div class="card-body p-4">
                            <form action="{{ url('dashboard') }}" method="POST">
                            {{ csrf_field() }}
                                <div class="form-group">
                                    <label for="emailaddress">E-mail</label>
                                    <input class="form-control" type="email" id="emailaddress" name="email" placeholder="Digite seu e-mail" autofocus>
                                </div>

                                <div class="form-group">
                                    <a href="pages-recoverpw.html" class="text-muted float-right"><small>Esqueceu sua senha?</small></a>
                                    <label for="password">Senha</label>
                                    <input class="form-control" type="password" name="senha" id="password" placeholder="Digite sua senha">
                                </div>

                                <div class="form-group mb-3">
                                    <div class="custom-control custom-checkbox">
                                        <input type="checkbox" class="custom-control-input" id="checkbox-signin" checked>
                                        <label class="custom-control-label" for="checkbox-signin">Lembrar- me</label>
                                    </div>
                                </div>

                                <div class="form-group mb-0 text-center">
                                    <button class="btn btn-primary" type="submit"> Entrar </button>
                                </div>

                            </form>
                        </div> <!-- end card-body -->
                    </div>
                    <!-- end card -->


                </div> <!-- end col -->
            </div>
            <!-- end row -->
        </div>
        <!-- end container -->
    </div>
    <!-- end page -->

@endsection

What are the next steps I should take? Can someone help me with this?

  • There is already the routine for this, why did you do so? I even think your doubt is repeated

  • Example 1: https://answall.com/questions/162965/laravel-authatempt-sempre-retorna-false/162970#162970

  • Example 2: https://answall.com/questions/206213/erro-auth-laravel-com-outra-model/206227#206227

  • I saw that you have Auth to perform authentication, but I would like to better understand how it works. Is there any way you can help me with this? If it’s repeated, can you show me where I can find it? I’ve just started messing with Laravel. I’m still studying. If you can help me, I’d appreciate it

  • Oops, Show. Thank you so much, Virgilio!

1 answer

0


Just so you understand, what would be the point of doing it this way? The Laravel documentation is very good, as soon as you run the php Artisan make:auth command it already creates the whole authentication system for you. It already creates the Authcontroller, protects the routes through the middleware and etc. https://laravel.com/docs/5.7/authentication P.s. MD5 Password? For security use the standard of bcrypt.

  • It’s just that I’m new in Laravel. I’m developing the project precisely to learn. I thought Laravel didn’t have this routine, as it already has, I thought it was great.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.