Todo:laravel built-in simple login

Source: Internet
Author: User

Todo:laravel built-in simple login


1. Activating the Laravel auth system laravel The new features of PHP trait built-in simple user login registration function, suitable for some systems that do not require complex user rights management, such as the company's internal simple management system. Run the following command:

PHP Artisan Make:auth

Run successfully display

Authentication scaffolding generated successfully.

2. Added in the routing code

Auth::routes ()

The main implementation of the permissions of the login, user registration, user exit
Login to access Http://127.0.0.1:8000/login:

User Registration Http://127.0.0.1:8000/register:

The/home page will not be accessible until login is successful, otherwise it will remain on the login page
3. Simple analysis of auth code, as long as the need to add the controller's PHP code to add the constructor auth code,

Can see Authorizesrequests, dispatchesjobs, validatesrequests are Trait;auth is in a middleware mode is added to the code, middleware is laravel to an important part, We can also create middleware for use. Laravel Middleware has auth,web,http,route,session,view and so on, creating a middleware approach is simple:

PHP Artisan make:middleware Middleware Name

4. Change the relevant page of the permission to Semantic-ui style, as long as the code under the Auth @ extends changed to @extends (' Layouts.main ') that is, the switch is very convenient.
5. Since PHP 5.4.0, PHP implements a code reuse method called trait. Trait is a code reuse mechanism that is prepared for PHP-like single-inheritance languages. Trait to reduce the limitations of single-inheritance languages, developers are free to reuse method in separate classes within different hierarchies. The semantics of Trait and class combinations define a way to reduce complexity, avoiding traditional multi-inheritance and Mixin class-related typical problems. Members that inherit from the base class are overwritten by the members that are inserted by trait. Precedence is the method from which the member of the current class overrides the trait, and trait overrides the inherited method. The trait used by Laravel Auth have Handlesauthorization,authenticatable,createsuserproviders,guardhelpers,canresetpassword, Trait is also very simple to use, as long as you add the name of using trait in class.
6. Simple system login is complete.

Wxgzh:ludong86

Todo:laravel built-in simple login

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.