管理员表设计
1.创建模型层和迁移文件
php artisan make:model Http\Model\Vuser -m
2.设计表字段
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('username',50)->default('')->comment('账号');
$table->string('truename',50)->default('')->comment('真实姓名');
$table->string('email',50)->default('')->comment('邮箱');
$table->string('phone',50)->default('')->comment('手机');
$table->string('password',250)->default('')->comment('密码');
$table->enum('sex',['男','女'])->default('男')->comment('性别');
$table->timestamps();
});
}
3.faker批量添加用户
(1.创建用户数据填充文件)
php artisan make:seeder UserSeeder
(2.数据填充文件修改)
<?php
use Illuminate\Database\Seeder;
use App\Http\Model\Vuser;
class VuserSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//清空数据表Z
Vuser::truncate();
//添加模拟数据
factory(Vuser::class,100)->create();
//规定id=1的用户名为admin
Vuser::where('id',1)->

本文介绍了在Laravel框架下如何设计管理员表,包括创建模型层和迁移文件,详细讲解了表字段的设计,并使用faker批量添加用户。在数据填充过程中,如果遇到字段长度问题,需要调整迁移文件。接着,文章阐述了实现用户登录的步骤,包括修改用户模型、创建控制器和方法、设计登录页面、分离验证提示以及配置路由。

282

被折叠的 条评论
为什么被折叠?



