php
主页 > 网络编程 > php >

Laravel框架Auth用户认证操作的教程方法

2019-09-29 | 秩名 | 点击:

(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

原文链接:https://www.cnblogs.com/gyfluck/p/9077642.html
相关文章
最新更新