Implement user registration and login through Laravel
This article shows us in detail the methods and steps for using Laravel to implement user registration and login. Friends in need can refer to it
Laravel is the most elegant PHP framework, and there are many Friends who are learning PHP are often salivating over Laravel. Come realize your wish today. Let us start from scratch and use Laravel to implement the most common registration and login functions of web applications! All course source codes have been placed on Github: laravel-start. Race Start!
Recommended related mysql video tutorials: "mysql tutorial"
First of all we Let’s clarify what we need for this course:
Laravel 4.2
Bootstrap 3.3
Laravel is the core part we care about. Bootstrap is used to quickly set some front-end CSS styles.
1. Install Laravel
After a brief explanation, let’s go to the next step and install Laravel. Here we install it through Composer, open the command line terminal, and execute:
1 |
|
Sites is the root directory of the web application. You can change it to your own root directory as needed, and then execute:
1 |
|
laravel is the name of your application directory, you can choose one A name you like. After executing the above command, wait for a while (after all, Internet speed is a big problem in China). After installation, you will get this bunch of directories:
Our main operations Three directories: models, controllers and views: this is the composition of MVC!
2. Install Bootstrap
Then execute from the command line:
1 |
|
The laravel here corresponds to the application directory above. If you are installing If you use another name, please change it accordingly. Go to the packages directory to install Bootstrap and execute it directly on the command line:
1 |
|
This is faster, and after this is downloaded, you will get the latest stable version of Bootstrap. Bower_components/bootstrap/dist/ in the packages directory contains Bootstrap's css, js, and fonts, three style files, js, and font files that we often use during the development process. After success, you will see this:
Note: The bower tool used here is responsible for managing some front-end packages.
At this point, our preliminary work is ready. But before going to the next step, we must first ensure that our laravel/app/storage directory has corresponding write permissions, so return to the laravel directory. If you have not touched the command line after installing bower, you can directly pass:
1 |
|
Go back to the laravel directory, and then execute:
1 |
|
After this step is completed, we can enter the real development stage.
3. Configure the database and create tables:
Before starting the configuration, we need to create a database for our laravel application, I named it laravel-start ,
Then open the app/config/database.php file in the editor and fill in the corresponding database configuration items, such as:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Connection After completing the database, you have to create a Users table. You can create the Users table directly in the database, or you can use Laravel's artisan to create it. Here we use Laravel's artisan to build the table, and learn a little bit about Laravel migrate. Execute the following statement:
php artisan migrate:make create-users-table
The above command will create a migrate file (the file is located in the app/database/migrations directory). The name of this file is create-users -table, then we can create the Users table by editing the migrate file we just generated.
1 2 3 4 5 6 7 8 9 10 |
|
The above method uses laravel's Schema Builder class. The above code uses the up() method to create a users table. There are 5 fields in this table: id auto-increment, username length within 20, The length of email should be within 100 and unique, and the length of password should be within 64. Remember_token is to make it more convenient and practical when logging in. Laravel will automatically fill in the token value, but at the beginning you must set a default value, timestamp the current timestamp. . One thing we need to pay attention to here is: It is best to add the following code to down() in case we need to delete the Users table one day.
1 2 3 4 |
|
After doing the above, execute the following magical command:
1 |
|
There are pictures and the truth:
Finally, we have finished the prelude and can officially come to Laravel.
4. Start the service and try it
Execute directly in the laravel directory:
1 |
|
Open the browser, enter localhost:8000, and press Enter. Bingo!
OK, give yourself thirty seconds of applause first, if you have successfully reached this step. Congratulations, you have entered the door of Laravel, we will come with more surprises one by one...
5. Create a public view
好了,我们现在开始了,首先在app/views/文件夹下创建一个layouts文件夹,再再这个文件夹下新建一个php文件,命名为main.blade.php,在这个文件里写上下面这些代码:
1 2 3 4 5 6 7 8 9 10 |
|
PS:layouts文件夹通常用来存放视图文件的功用部分,比如一些网页的头部

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Method for obtaining the return code when Laravel email sending fails. When using Laravel to develop applications, you often encounter situations where you need to send verification codes. And in reality...

LaravelEloquent Model Retrieval: Easily obtaining database data EloquentORM provides a concise and easy-to-understand way to operate the database. This article will introduce various Eloquent model search techniques in detail to help you obtain data from the database efficiently. 1. Get all records. Use the all() method to get all records in the database table: useApp\Models\Post;$posts=Post::all(); This will return a collection. You can access data using foreach loop or other collection methods: foreach($postsas$post){echo$post->

How to check the validity of Redis connections in Laravel6 projects is a common problem, especially when projects rely on Redis for business processing. The following is...

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

A problem of duplicate class definition during Laravel database migration occurs. When using the Laravel framework for database migration, developers may encounter "classes have been used...

Efficiently process 7 million records and create interactive maps with geospatial technology. This article explores how to efficiently process over 7 million records using Laravel and MySQL and convert them into interactive map visualizations. Initial challenge project requirements: Extract valuable insights using 7 million records in MySQL database. Many people first consider programming languages, but ignore the database itself: Can it meet the needs? Is data migration or structural adjustment required? Can MySQL withstand such a large data load? Preliminary analysis: Key filters and properties need to be identified. After analysis, it was found that only a few attributes were related to the solution. We verified the feasibility of the filter and set some restrictions to optimize the search. Map search based on city

How does Laravel play a role in backend logic? It simplifies and enhances backend development through routing systems, EloquentORM, authentication and authorization, event and listeners, and performance optimization. 1. The routing system allows the definition of URL structure and request processing logic. 2.EloquentORM simplifies database interaction. 3. The authentication and authorization system is convenient for user management. 4. The event and listener implement loosely coupled code structure. 5. Performance optimization improves application efficiency through caching and queueing.

When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.
