Laravel Login And Registration Tutorial Example (Logout Forgot Password)

Create Laravel Login And Registration Tutorial With Example.

Today, we will create a full login and register example in laravel. It will include functionalities like registration, login, logout, remember me and forgot password.

It is very simple to implement authentication process in laravel. We just need to trigger one command and make database connection. All files will be generated automatically.

You need to have installed laravel and MySQL database. If not, then checkout

First of all, watch the below video which is the look and feel of our example tutorial.

Now, walk through all the below moves to accomplish your goal.

Move 1. Make a fresh laravel project

Create new laravel project by below command

Move 2. Make Database and change .env file

Now it is time to create a database and connect it with the laravel project.

  • I am using sequal pro for database management. You might use phpMyAdmin and that is perfectly ok.
  • Just make a new database and give it a name “registerMysql”
  • To connect this database with our project, we need to change .env file of project.
  • Open this .env file and navigate to DB_CONNECTION keyword.

See the below source code

  • You need to update above values in your project’s .env file.
  • I have not any password so I have left it empty.

Move 3. Authentication command

Go to your terminal and hit the below command

  • This command will create some files automatically. We will see this files later.

Now run the following command

  • When you trigger above command, compiler will connect our database with laravel project and will also create some tables into the database.

Move 4. Generated Files

At this point, we have successfully created our example and you can check registration , login, logout etc. functionalities.

  • Let us now see which files are automatically generated by compiler.
  • Navigate to Http->Controller->Auth directory.
  • Inside Auth folder, you will find some php files like RegisterController.php, LoginController.php, ForgotPasswordController.php etc.
  • All These files will control the flow of the functionalities. You customize these files as per your requirement.

For example, when user register successfully, below code is redirecting him to home page.

  • You can edit above code to redirect user to other than home page or any other functionality you want to execute after successful registration.

Similarly, you can edit other controller files.

Move 5. View files

Along with controllers, compiler also have created some blade view files.

  • Navigate to resources->views->auth directory.
  • Inside auth folder, you will find some blade files like login.blade.php, register.blade.php etc.
  • These files are creating design for various pages and you can edit them to make your custom design with html, css and other front end resources.
  • Now go to the routes->web.php

This file have all the routes definitions.

You will find below line in this web.php file.

  • This one single line includes various routes like after login, after register, after forgot password etc.

To see these routes, hit the below command in your terminal

You will see the below output

  • So you can see all the routes in above snippet.

As you have seen that creating a register and login task is very simple in laravel. You just need to hit one command and create a database. That is it, all other tasks are automatically.

Download Source Code for laravel login and registration

Click this github link for source code

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *