Skip to content

Commit

Permalink
分类模型和数据
Browse files Browse the repository at this point in the history
  • Loading branch information
summerblue committed Sep 19, 2019
1 parent 4cf779f commit 4dd9f58
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/Models/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
protected $fillable = [
'name', 'description',
];
}
23 changes: 23 additions & 0 deletions database/migrations/2019_09_19_191731_create_categories_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCategoriesTable extends Migration
{
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->index()->comment('名称');
$table->text('description')->nullable()->comment('描述');
$table->integer('post_count')->default(0)->comment('帖子数');
});
}

public function down()
{
Schema::dropIfExists('categories');
}
}
37 changes: 37 additions & 0 deletions database/migrations/2019_09_19_192022_seed_categories_data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class SeedCategoriesData extends Migration
{
public function up()
{
$categories = [
[
'name' => '分享',
'description' => '分享创造,分享发现',
],
[
'name' => '教程',
'description' => '开发技巧、推荐扩展包等',
],
[
'name' => '问答',
'description' => '请保持友善,互帮互助',
],
[
'name' => '公告',
'description' => '站点公告',
],
];

DB::table('categories')->insert($categories);
}

public function down()
{
DB::table('categories')->truncate();
}
}

0 comments on commit 4dd9f58

Please sign in to comment.