Skip to content

Commit f1fe975

Browse files
committed
Factories and renaming migration tables
1 parent fa3b5f9 commit f1fe975

9 files changed

+69
-57
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
use Chrisjk123\Blogger\Category;
4+
use Faker\Generator as Faker;
5+
use Illuminate\Support\Str;
6+
7+
$factory->define(Category::class, function (Faker $faker) {
8+
$title = $faker->name;
9+
10+
return [
11+
'title' => $title,
12+
'slug' => Str::slug($title),
13+
'parent_id' => null,
14+
];
15+
});

database/factories/PostFactory.php

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
11
<?php
22

3-
$factory->define(Chrisjk123\Blogger\Tag::class, function (Faker $faker) {
4-
$noteable = [
5-
App\Complex::class,
6-
];
7-
$noteableType = $faker->randomElement($noteables);
8-
$noteable = factory($noteableType)->create();
9-
10-
return [
11-
'noteable_type' => $noteableType,
12-
'noteable_id' => $noteable->id,
13-
...
14-
];
15-
});
16-
17-
$factory->define(Chrisjk123\Blogger\Category::class, function (Faker $faker) {
18-
$title = $faker->name;
19-
20-
return [
21-
'title' => $title,
22-
'slug' => str_slug($title),
23-
'parent_id' => null,
24-
];
25-
});
3+
use Chrisjk123\Blogger\Category;
4+
use Chrisjk123\Blogger\Post;
5+
use Faker\Generator as Faker;
6+
use Illuminate\Support\Str;
267

27-
$factory->define(Chrisjk123\Blogger\Post::class, function (Faker\Generator $faker) {
8+
$factory->define(Post::class, function (Faker $faker) {
289
$title = $faker->name;
2910

3011
return [
3112
'title' => $title,
32-
'slug' => str_slug($title),
13+
'slug' => Str::slug($title),
3314
'excerpt' => $faker->name,
3415
'content' => $faker->paragraph,
35-
'category_id' => factory('Chrisjk123\Blogger\Category')->create()->id,
16+
'category_id' => factory(Category::class)->create()->id,
3617
];
3718
});

database/factories/TagFactory.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
use Chrisjk123\Blogger\Tag;
4+
use Faker\Generator as Faker;
5+
6+
$factory->define(Tag::class, function (Faker $faker) {
7+
return [
8+
'name' => $faker->name,
9+
];
10+
});

database/factories/UserFactory.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

database/migrations/2019_12_28_101010_create_posts_table.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ public function up()
1515
{
1616
Schema::create('posts', function (Blueprint $table) {
1717
$table->increments('id');
18+
$table->integer('category_id');
1819

19-
$table->string('title');
20+
$table->string('name');
2021
$table->string('slug');
2122
$table->string('excerpt');
2223
$table->text('content');
24+
$table->string('status');
2325

24-
$table->integer('category_id');
26+
$table->timestamp('published_at');
2527

2628
$table->timestamps();
2729
$table->softDeletes();

database/migrations/2019_12_28_101011_create_categories_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function up()
1515
{
1616
Schema::create('categories', function (Blueprint $table) {
1717
$table->increments('id');
18-
$table->string('title');
18+
$table->string('name');
1919
$table->string('slug')->nullable();
2020
$table->index('parent_id');
2121
$table->timestamps();

database/migrations/2019_12_28_101012_create_comments_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function up()
1515
{
1616
Schema::create('comments', function (Blueprint $table) {
1717
$table->increments('id');
18-
$table->string('body');
18+
$table->string('content');
1919
$table->integer('commentable_id');
2020
$table->string('commentable_type');
2121
$table->timestamps();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use Chrisjk123\Blogger\Category;
4+
use Chrisjk123\Blogger\Post;
5+
use Chrisjk123\Blogger\Tag;
6+
use Illuminate\Database\Seeder;
7+
8+
class PostsTableSeeder extends Seeder
9+
{
10+
/**
11+
* Run the database seeds.
12+
*
13+
* @return void
14+
*/
15+
public function run()
16+
{
17+
factory(Tag::class, 25)->create();
18+
19+
factory(Category::class, 12)->create();
20+
21+
factory(Post::class, 200)->create();
22+
}
23+
}

src/BloggerServiceProvider.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ public function boot()
1414
$this->publishes([
1515
__DIR__.'/../database/migrations/' => database_path('migrations'),
1616
], 'migrations');
17+
18+
$this->publishes([
19+
__DIR__.'/../database/factories/' => database_path('factories'),
20+
], 'factories');
21+
22+
$this->publishes([
23+
__DIR__.'/../database/seeds/' => database_path('seeds'),
24+
], 'seeders');
1725
}
1826

1927
/**

0 commit comments

Comments
 (0)