Created
December 12, 2020 20:05
-
-
Save alqahtani/d64840b3f7744e0e6c069dab9ed70013 to your computer and use it in GitHub Desktop.
Following with build forum with TDD on Laracasts
This file contains hidden or 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
| <?php | |
| namespace Database\Factories; | |
| use App\Models\User; | |
| use App\Models\Reply; | |
| use App\Models\Thread; | |
| use Illuminate\Database\Eloquent\Factories\Factory; | |
| class ReplyFactory extends Factory | |
| { | |
| /** | |
| * The name of the factory's corresponding model. | |
| * | |
| * @var string | |
| */ | |
| protected $model = Reply::class; | |
| /** | |
| * Define the model's default state. | |
| * | |
| * @return array | |
| */ | |
| public function definition() | |
| { | |
| return [ | |
| 'user_id' => User::factory(), | |
| 'thread_id' => Thread::factory(), | |
| 'body' => $this->faker->paragraph() | |
| ]; | |
| } | |
| } |
This file contains hidden or 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
| <?php | |
| namespace Database\Factories; | |
| use App\Models\User; | |
| use App\Models\Thread; | |
| use Illuminate\Database\Eloquent\Factories\Factory; | |
| class ThreadFactory extends Factory | |
| { | |
| /** | |
| * The name of the factory's corresponding model. | |
| * | |
| * @var string | |
| */ | |
| protected $model = Thread::class; | |
| /** | |
| * Define the model's default state. | |
| * | |
| * @return array | |
| */ | |
| public function definition() | |
| { | |
| return [ | |
| 'user_id' => User::factory(), | |
| 'title' => $this->faker->sentence(), | |
| 'body' => $this->faker->paragraph() | |
| ]; | |
| } | |
| } |
This file contains hidden or 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
| <?php | |
| // first command to create threads | |
| $threads = App\Models\Thread::factory()->count(50)->create(); | |
| // second command to create replies for the created threads | |
| $threads->each(function($thread) { App\Models\Reply::factory()->count(10)->create(['thread_id'=> $thread->id]); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment