Skip to content

Commit b14b42e

Browse files
committed
Migrations and seeders finished
1 parent f1fe975 commit b14b42e

8 files changed

+58
-29
lines changed

README.md

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
# Very short description of the package
1+
# Add blog database tables to a Laravel app
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/chrisjk123/blogger.svg?style=flat-square)](https://packagist.org/packages/chrisjk123/blogger)
44
[![Build Status](https://img.shields.io/travis/chrisjk123/blogger/master.svg?style=flat-square)](https://travis-ci.org/chrisjk123/blogger)
55
[![Quality Score](https://img.shields.io/scrutinizer/g/chrisjk123/blogger.svg?style=flat-square)](https://scrutinizer-ci.com/g/chrisjk123/blogger)
66
[![Total Downloads](https://img.shields.io/packagist/dt/chrisjk123/blogger.svg?style=flat-square)](https://packagist.org/packages/chrisjk123/blogger)
77

8-
This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.
8+
9+
This package offers fully blog database tables as well as preset models with relations, scopes and seeders.
10+
11+
## Requirements
12+
13+
This package requires Laravel 5.8 or higher, PHP 7.2 or higher and a database that supports json fields and MySQL compatible functions.
914

1015
## Installation
1116

@@ -15,29 +20,38 @@ You can install the package via composer:
1520
composer require chrisjk123/blogger
1621
```
1722

23+
You can publish the migrations with:
24+
1825
```bash
19-
php artisan vendor:publish --provider="Chrisjk123\Blogger\BloggerServiceProvider"
26+
php artisan vendor:publish --provider="Chrisjk123\Blogger\BloggerServiceProvider" --tag="migrations"
2027
```
2128

22-
## Usage
29+
Publish the migrations:
2330

24-
``` php
25-
// Usage description here
31+
```bash
32+
php artisan migrate
2633
```
2734

28-
### Testing
35+
You can publish the factories with:
2936

30-
``` bash
31-
composer test
37+
```bash
38+
php artisan vendor:publish --provider="Chrisjk123\Blogger\BloggerServiceProvider" --tag="factories"
3239
```
3340

34-
### Changelog
41+
You can publish the seeder with:
3542

36-
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
43+
```bash
44+
php artisan vendor:publish --provider="Chrisjk123\Blogger\BloggerServiceProvider" --tag="seeders"
45+
```
3746

38-
## Contributing
47+
## Usage
3948

40-
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
49+
``` php
50+
// Usage description here
51+
```
52+
### Changelog
53+
54+
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
4155

4256
### Security
4357

@@ -51,7 +65,3 @@ If you discover any security related issues, please email christopherjk123@gmail
5165
## License
5266

5367
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
54-
55-
## Laravel Package Boilerplate
56-
57-
This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

database/factories/CategoryFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
$title = $faker->name;
99

1010
return [
11-
'title' => $title,
11+
'name' => $title,
1212
'slug' => Str::slug($title),
1313
'parent_id' => null,
1414
];
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\Comment;
4+
use Faker\Generator as Faker;
5+
6+
$factory->define(Comment::class, function (Faker $faker) {
7+
return [
8+
'content' => $faker->paragraph,
9+
];
10+
});

database/factories/PostFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
$title = $faker->name;
1010

1111
return [
12-
'title' => $title,
12+
'category_id' => factory(Category::class)->create()->id,
13+
'name' => $title,
1314
'slug' => Str::slug($title),
1415
'excerpt' => $faker->name,
1516
'content' => $faker->paragraph,
16-
'category_id' => factory(Category::class)->create()->id,
17+
'status' => 'published',
18+
'published_at' => now(),
1719
];
1820
});

database/migrations/2019_12_28_101010_create_posts_table.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ public function up()
1919

2020
$table->string('name');
2121
$table->string('slug');
22-
$table->string('excerpt');
23-
$table->text('content');
24-
$table->string('status');
22+
$table->string('excerpt')->nullable();
23+
$table->text('content')->nullable();
24+
$table->string('status')->nullable();
2525

2626
$table->timestamp('published_at');
27-
2827
$table->timestamps();
2928
$table->softDeletes();
3029
});

database/migrations/2019_12_28_101011_create_categories_table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function up()
1717
$table->increments('id');
1818
$table->string('name');
1919
$table->string('slug')->nullable();
20+
$table->integer('parent_id')->nullable();
2021
$table->index('parent_id');
2122
$table->timestamps();
2223
});

database/migrations/2019_12_28_101013_create_tags_table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function up()
1616
Schema::create('tags', function (Blueprint $table) {
1717
$table->increments('id');
1818
$table->string('name');
19+
$table->timestamps();
1920
});
2021

2122
Schema::create('taggables', function (Blueprint $table) {

database/seeds/PostsTableSeeder.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
use Chrisjk123\Blogger\Category;
3+
use Chrisjk123\Blogger\Comment;
44
use Chrisjk123\Blogger\Post;
55
use Chrisjk123\Blogger\Tag;
66
use Illuminate\Database\Seeder;
@@ -14,10 +14,16 @@ class PostsTableSeeder extends Seeder
1414
*/
1515
public function run()
1616
{
17-
factory(Tag::class, 25)->create();
17+
factory(Post::class, 20)
18+
->create()
19+
->each(function ($post) {
20+
$post->tags()->sync(
21+
factory(Tag::class, 4)->create()->pluck('id')->toArray()
22+
);
1823

19-
factory(Category::class, 12)->create();
20-
21-
factory(Post::class, 200)->create();
24+
$post->comments()->save(factory(Comment::class)->make());
25+
$post->comments()->save(factory(Comment::class)->make());
26+
$post->comments()->save(factory(Comment::class)->make());
27+
});
2228
}
2329
}

0 commit comments

Comments
 (0)