laravel身份证验证_简单的Laravel登录身份验证

laravel身份证验证

This article has been upgraded to work with Laravel 4.1.26
本文已升级为可与Laravel 4.1.26一起使用

Today we'll be creating a simple Laravel authentication. Using migrations, seeding, routes, controllers, and views, we'll walk through the entire process.

今天,我们将创建一个简单的Laravel身份验证。 使用迁移,播种,路由,控制器和视图,我们将逐步完成整个过程。

This tutorial will walk us through:

本教程将引导我们完成:

  • Creating a users table using migrations

    使用迁移创建用户表
  • Filling our new users table with sample users using seeding

    使用种子填充示例用户来填充我们的新用户表
  • Using the great artisan command line tool to migrate and seed

    使用出色的artisan命令行工具进行迁移和播种
  • Creating a login form and processing a login using routes, controllers, and views

    使用路由,控制器和视图创建登录表单并处理登录
  • Handling login errors

    处理登录错误
  • Use Eloquent ORM to validate a user

    使用雄辩的ORM验证用户

准备我们的数据库 ( Getting our Database Ready )

To get our authentication working, we will need to have a database and users to login with.

为了使我们的身份验证有效,我们将需要有一个数据库和用于登录的用户。

数据库设置 (Database Setup)

Set up your database and user. Assign that user to the database and make sure you update your settings in app/config/database.php.

设置您的数据库和用户。 将该用户分配给数据库,并确保您更新app/config/database.php

移居 (Migrations)

Migrations are a way we can manipulate our database within our codebase. This means we don't have to get our hands dirty by doing any SQL commands or messing around inside a tool like phpmyadmin. For more information and the benefits of migrations, see the official docs.

迁移是我们可以在代码库中操作数据库的一种方式。 这意味着我们不必通过执行任何SQL命令或在诸如phpmyadmin之类的工具中弄乱自己的手。 有关更多信息以及迁移的好处,请参见官方文档

Migrations are very easy to create. The easiest way to create a migration will be to use the great artisan command line interface created by Taylor Otwell. To create the migration, via the command line, in the root folder of your application, simply type:

迁移非常容易创建。 创建迁移的最简单方法是使用Taylor Otwell创建的出色的工匠命令行界面。 要通过命令行在应用程序的根文件夹中创建迁移 ,只需键入:

php artisan migrate:make create_users_table ––create=users

php artisan migrate:make create_users_table ––create=users

This will automatically create a migrations file inside of your app/database/migrations folder. Let's take a look at the newly created file.

这将在您的app/database/migrations文件夹内自动创建一个迁移文件。 让我们看一下新创建的文件。

// app/database/migrations/####_##_##_######_create_users_table.php

<?php

use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;

class CreateUsersTable extends Migration {

  /**
   * Run the migrations.
   *
   * @return void
   */
  public function up()
  {
      Schema::create('users', function(Blueprint $table)
      {
          $table->increments('id');
          $table->timestamps();
      });
  }

  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down()
  {
      //
  }

}

Laravel generates the core of the migration file for you and the --create command will let the migration create the table for you. It will create a table for you with an id field and the timestamps field. This will make created_at and updated_at fields. Now we use the Schema Builder to create our users table.

Laravel为您生成迁移文件的核心,而--create命令将使迁移为您创建表。 它将为您创建一个具有id字段和timestamps字段的表。 这将创建created_at和Updated_at字段。 现在,我们使用Schema Builder创建我们的users表。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Laravel 中进行邮箱验证可以通过以下步骤实现: 1. 在控制器中定义验证规则: ```php $rules = [ 'email' => 'required|email|unique:users,email', ]; ``` 2. 在控制器中引入 Validator 并使用 validate 方法进行验证: ```php use Illuminate\Support\Facades\Validator; $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { return redirect()->back()->withErrors($validator); } // 验证通过,继续执行其他操作 ``` 3. 在表单中添加邮箱输入框并设置 name 属性为 email: ```html <form action="/register" method="POST"> @csrf <label for="email">邮箱</label> <input type="email" name="email" id="email"> <button type="submit">注册</button> </form> ``` 4. 在邮箱验证邮件中添加验证链接并发送给用户: ```php use Illuminate\Support\Facades\Mail; use App\Mail\VerificationEmail; Mail::to($user->email) ->send(new VerificationEmail($user->verification_token)); ``` 5. 创建 VerificationEmail 类并定义邮件内容及验证链接: ```php use Illuminate\Mail\Mailable; class VerificationEmail extends Mailable { public $verificationToken; public function __construct(string $verificationToken) { $this->verificationToken = $verificationToken; } public function build() { $url = route('verify-email', $this->verificationToken); return $this->view('emails.verification', ['url' => $url]); } } ``` 6. 创建邮箱验证路由并处理验证逻辑: ```php use App\Models\User; Route::get('/verify-email/{token}', function ($token) { $user = User::where('verification_token', $token)->first(); if (!$user) { abort(404); } $user->update(['verification_token' => null]); return view('emails.verification-success'); })->name('verify-email'); ``` 以上就是 Laravel 中进行邮箱验证的基本步骤,具体实现可能会有所不同,但大致思路是相似的。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值