1. 生成 Auth 所需文件;
在 Artisan 控制台输入命令:php artisan make:auth
cd /data/project/test/laravel1
php artisan make:auth
此时在 routes/web.php
会自动生成以下代码
Auth: : routes ( ) ;
Route: : get ( '/home' , 'HomeController@index' ) - > name ( 'home' ) ;
resources/views/
目录以及 App/Http/Controllers/
都会生成相关文件 访问:http://192.168.1.214:2000/home 此页面提供了登录、注册、找回密码等功能 生成此页面功能对应的表,需要使用迁移功能 database/migrations/
下存放数据迁移文件
php artisan migrate
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table
2. 数据迁移;
CREATE TABLE IF NOT EXISTS students (
`id` INT AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR ( 32 ) NOT NULL DEFAULT '' COMMENT '姓名' ,
`age` TINYINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '年龄' ,
`gender` TINYINT UNSIGNED NOT NULL DEFAULT 10 COMMENT '性别' ,
`created_at` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '创建时间' ,
`updated_at` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '修改时间'
) ENGINE = InnoDB DEFAULT CHARSET = UTF8 AUTO_INCREMENT = 1001 COMMENT = '学生表' ;
php artisan make: migration create_students_table -- create= students
public function up ( )
{
Schema: : create ( 'students' , function ( Blueprint $table ) {
$table - > bigIncrements ( 'id' ) ;
$table - > string ( 'name' ) ;
$table - > integer ( 'age' ) - > unsigned ( ) - > default ( 0 ) ;
$table - > integer ( 'gender' ) - > default ( 10 ) ;
$table - > integer ( 'created_at' ) - > default ( 0 ) ;
$table - > integer ( 'updated_at' ) - > default ( 0 ) ;
} ) ;
}
php artisan migrate
php artisan make:model Article -m
3. 数据填充。
php artisan make: seeder StudentTableSeeder
public function run ( )
{
DB : : table ( 'students' ) - > insert ( [
[ 'name' = > 'test1' , 'age' = > 18 ] ,
[ 'name' = > 'test2' , 'age' = > 19 ] ,
] ) ;
}
php artisan db:seed --class= StudentTableSeeder
public function run ( )
{
$this - > call ( StudentTableSeeder: : class ) ;
}
php artisan db: seed