Authentication in laravel

To create registration page in laravel, you’ll need to follow a few steps. Here is basic outline of the process.

Create your project using this command: via the Composer create-project command:

[snippet slug=9200 lang=abap]

Run these commands on the terminal to run your project::

[snippet slug=login lang=abap]

Create a database file and set the configurations inside .env file in your project:

[snippet slug=env lang=abap]

Laravel follows Model View Controller Structure.

VIEW:  The View is responsible for presenting the data to the user in a readable format.

CONTROLLER: The Controller handles the user’s requests and acts as an intermediary between the Model and the View. It receives input from the user, processes it, interacts with the Model to fetch or manipulate data, and then passes the data to the View for rendering.

MODEL: It is responsible for interacting with the database or any other data source, performing data manipulation, and enforcing data validation rules. In Laravel, models are typically created as classes extending the Illuminate\Database\Eloquent\Model base class. They define the structure of database tables and provide methods to query and manipulate data.

STEP 1: CREATE REGISTER VIEW PAGE FOR REGISTRATION 

Here we create a layout file in which we can write common code.

[snippet slug=login5-2 lang=abap]

STEP 2: CREATE CONTROLLER RELATED TO REGISTER VIEW PAGE:

We need to create a Controller to handle our form data. From View Files, When we submit our form data, it goes to Controller. We can make the controller by using the following command: php artisan make:controller AuthController.

You will find your controller under App > http > Controller > AuthController

[snippet slug=login3 lang=abap]

STEP 3: CREATE ROUTES FOR VIEW AND CONTROLLER FILES:

To access the Registration view files and its related controller we need to create routes in web.php file. Open routes > web.php

[snippet slug=login4-2 lang=abap]

create the register() to view your page and store() to handle the data. For Example, function store() will handle registration data .In this function, we will store the user’s data and then pass that data to the data table to store it in the database using Model. So we need to create a Model for that particular data table in which we want to store our user’s data.

STEP 4: CREATE MODEL:

We can create a model by using the following command: Php artisan make:model model name. Import model to your controller.

[snippet slug=login7 lang=abap]

So once the user submits the registration form, the controller action responsible for handling the registration process, it will create a new user record in the database. Then redirect the user to another page, such as a home page or a login page.

LOGIN:

  1. After successfully done with registration, we can login. Login will also follow the same steps
  2. If the user login with email id and password, which has been registered, he will be logged in successfully and redirect in home page and in another page.

STEP 1: CREATE LOGIN VIEW PAGE

Here we create a layout file in which we can write common code for login.

[snippet slug=login-blade lang=abap]

STEP 2: CREATE CONTROLLER RELATED TO LOGIN VIEW PAGE:

[snippet slug=login-controller lang=abap]

STEP 3: CREATE ROUTES FOR VIEW AND CONTROLLER FILES:

[snippet slug=login-routes lang=abap]

Leave a Reply