Laravel 开发记录2

Migrations数据迁移创建数据表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
uiste:blog uiste$ php artisan make:migration create_links_table
Created Migration: 2015_11_15_033430_create_links_table

---
public function up()
{
Schema::create('links', function (Blueprint $table) {
$table->engine = 'MyISAM';
$table->increments('link_id');
$table->string('link_name')->default('')->comment('名称');
$table->string('link_title')->default('')->comment('标题');
$table->string('link_url')->default('')->comment('链接');
$table->integer('link_order')->default(10)->comment('排序');
});
}

---
Migration table created successfully.
Migrated: 2015_11_15_033430_create_links_table

数据填充

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
uiste:blog uiste$ php artisan make:seeder LinksTableSeeder
Seeder created successfully.

---
public function run()
{
$data = [
[
'link_name' => 'uiste技术博客',
'link_title'=> '专注于技术分享,实战经验总结',
'link_url' => 'http://blog.uiste.com',
'link_order'=> 1,
],
[
'link_name' => 'uiste生活博客',
'link_title'=> '分享生活,欣赏一切美好的事物',
'link_url' => 'http://www.uiste.com',
'link_order'=> 2,
]
];
DB::table('links') -> insert($data);
}

---
public function run()
{
$this->call(LinksTableSeeder::class);
}

---
uiste:blog uiste$ php artisan db:seed
Seeded: LinksTableSeeder