laravel身份证验证
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表。