laravel批量添加加登陆
1.管理员表设计
创建生成模型和迁移文件
php artisan make:model Models/User -m
Schema::create(‘users’, function (Blueprint $table) {
$table->bigIncrements(‘id’);
$table->string(‘username’,50);
$table->string(‘truename’,50)->default(‘未知’);
$table->string(‘password’,255);
$table->string(‘email’,50)->nullable();
$table->string(‘phone’,255)->default(’’);
$table->enum(‘sex’,[‘先生’,‘女士’])->default(‘先生’)->comment(‘性别’);
$table->char(‘last_ip’,15)->default(’’);
$table->timestamps();
// 软删除
$table->softDeletes();
});
2.faker批量添加用户
创建用户的数据填充文件
php artisan make:seeder UserSeeder
修改模型
生成一个数据工厂
php artisan make:factory UserFactory -m Models/User
数据填充文件修改
修改总调用
执行填充
php artisan db:seed
3.实现登录
使用laravel提供一个登录方法 auth()登录
修改用户模型的父类
配置config/auth.php文件
定义后台的路由文件
在routes/web.php路由文件中引入自定义分层的路由文件
创建控制器和对应的方法
定义模板
实现登录
表单验证
前台的显示
让验证提示独立出来
在想要显示的模板页面中引入 @include
实现登录PHP代码编写
到这里就结束啦,记得点赞转发!!!