Skip to content

Commit fa3b5f9

Browse files
committed
WIP: Factory and relation testing
1 parent dbe5af1 commit fa3b5f9

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

database/factories/PostFactory.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
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+
});
26+
27+
$factory->define(Chrisjk123\Blogger\Post::class, function (Faker\Generator $faker) {
28+
$title = $faker->name;
29+
30+
return [
31+
'title' => $title,
32+
'slug' => str_slug($title),
33+
'excerpt' => $faker->name,
34+
'content' => $faker->paragraph,
35+
'category_id' => factory('Chrisjk123\Blogger\Category')->create()->id,
36+
];
37+
});

database/factories/UserFactory.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/** @var \Illuminate\Database\Eloquent\Factory $factory */
4+
use App\User;
5+
use Faker\Generator as Faker;
6+
use Illuminate\Support\Str;
7+
8+
/*
9+
|--------------------------------------------------------------------------
10+
| Model Factories
11+
|--------------------------------------------------------------------------
12+
|
13+
| This directory should contain each of the model factory definitions for
14+
| your application. Factories provide a convenient way to generate new
15+
| model instances for testing / seeding your application's database.
16+
|
17+
*/
18+
19+
$factory->define(User::class, function (Faker $faker) {
20+
return [
21+
'name' => $faker->name,
22+
'email' => $faker->unique()->safeEmail,
23+
'email_verified_at' => now(),
24+
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
25+
'remember_token' => Str::random(10),
26+
];
27+
});

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('name');
18+
$table->string('title');
1919
$table->string('slug')->nullable();
2020
$table->index('parent_id');
2121
$table->timestamps();

0 commit comments

Comments
 (0)