本篇文章小编给大家分享一下Laravel框架Auth用户认证代码实例,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
具体代码如下:
(1)生成Auth所需文件
打开phpstorm的命令行:
php artisan make:auth
生成成功后,打开web.php,
发现多了如下代码:
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
然后访问 localhost/laravel/public/home就可以看到登录页面,
如果样式不正常,需要修改layouts/app.blade.php的css路径。
php artisan migrate
会生成数据表,就可以注册登录了。
(2)数据迁移
方法一、新建一个teachers表迁移文件
php artisan make:migration create_teachers_table
示例:
php artisan make:migration create_teachers_table --create=teachers
在database目录下的migrations目录下会多一个文件
2018_05_23_091955_create_teachers_table.php
然后打开这个文件,修改up方法,编辑表结构:
public function up()
{
Schema::create('teachers', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('age')->unsigned()->default(0);
$table->integer('sex')->unsigned()->default(1);
$table->integer('create_at')->unsigned()->default(0);
$table->integer('update_at')->unsigned()->default(0);
});
}
然后执行迁移文件
php artisan migrate,
数据库就会多出来一个数据表。
方法二、生成模型的同时生成迁移文件
php artisan make:model School -m
示例:
php artisan make:model School -m
在database目录下的migrations目录下会多一个文件
2018_05_23_092252_create_schools_table.php
(3)数据填充
创建一个填充文件,并完善填充文件
php artisan make:seeder StudentTableSeeder
执行单个填充文件
php artisan db:seed --class=StudentTableSeeder
批量执行填充文件
php artisan db:seed
韩剧再婚皇后阿里云盘全集高清1080P资源链接-韩剧再婚皇后免费阿里云盘资源下载4K高清无删减版链接
poipiku网站如何打开-poipiku官网网页版访问入口
明日方舟:终末地-云游戏畅玩入口-明日方舟:终末地-网页版在线直连地址
poki在线小游戏网页版-poki免费游戏大全入口
poki游戏入口-点开即玩-poki游戏-在线免费畅玩
原神akt大佬资源viciNeko入口链接-原神akt大佬资源网页vicineko入口链接分享