Quick Contact

    Use of auth with example

    In many languages basic user authentication system with registration login sessions, password resets and access permissions consumes a lot of time. Laravel found a way to make authentication very easy to use and to understand whether you have freshly installed Laravel project or the project you are running. Laravel projects always have a create user table migration and a user model. There are a lot of different ways how you could pull in a login and register system ui which can be done through bootstrap.

    Let’s write down php artisan ui. So create me a ui of tailwind as-:

    • Php artisan uitailwindcss –auth and press enter and it will create the ui-:

    As you can see in last line that please run npm to compile your fresh scaffholding. Copy it and paste it down and enter and npm is running. So, let’s open a new tab and go to desktop/workspace/cars and you can get your ui very fast. But if you want to start off with the user model and user migration. For migration let’s open the database folder- migrations and see which one is the create user’s table. So, first one, creating our table users with an id name, a unique email timestamp where the email has been verified a password, the remembered token and timestamps as-:

    So, this covers everything you need to handle basic user authentication.

    In most applications, first migration that Laravel automatically created for us is the users table, It also. So, let’s open models, let’s open user.php and there you can see a bit more code which was user used to created while creating a model as-:

    It is a little bit more complex. As usually user required to fill email and password and token needs to be hidden. Before proceeding understand the words authentication and authorization. Whenever you want to authenticate you are basically verifying what someone is and then you will allow them to act as a person inside your application, think about login and logout process, it allows the users to identify themselves during the time they use your application. Whereas authorization means that you are going to determine whether authenticated user is allowed. So authorized to perform specific behavior in the application. For example adding an access type to the application that makes a user enter specific pages on the application.

    Now comes important part i.e. authenticatable file. As in above code what the authenticatable means? A non-coder will say that it is not very important but in code or file there are three different files are implemented,

    in which first one is authenticable contract, it requires important methods that allows framework to authenticate instances of this model to the authentication system. So it has files as authenticatable contract which allows framework to authorize instances of this model for their access permission in different contexts, authorizable contract and finally reset password contract in which there will two methods are applied, the get gmail for password reset and send password reset notifications that allows framework to reset the password of an entity that satisfies this contract.

    Moreover now if you go to routes, open web.php file and write their php artisan route list to see all the routes then first clear all older routes with “artisan route: clear” and then perform “php artisan optimize” and see php artisan route calling list one more time. You can see all the routes has been created including the login register password reset and way more.

    Copyright 1999- Ducat Creative, All rights reserved.