forked from summerblue/larabbs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cf779f
commit 4dd9f58
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
database/migrations/2019_09_19_191731_create_categories_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
37
database/migrations/2019_09_19_192022_seed_categories_data.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |