Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ezat's avatar
Level 1

PHP error: Undefined variable: threads on line 1

Hi, I am working with Let's Build A Forum with Laravel and TDD Jeffrey way lessons and when I am running $threads->each(function ($thread) { factory('App\Reply', 10)->create(['thread_id' => $thread->id]);}); In my tinker i get The error "PHP error: Undefined variable: threads on line 1" Can any one help me with this Please?

0 likes
3 replies
sutherland's avatar
Level 28

What did you run just before? You probably need to run this before:

$threads = factory('App\Thread', 10)->create();

If you already have threads in your database, you can just do

$threads = Thread::all();

Remember that when you exit tinker any variables you've set will be gone.

4 likes
Ezat's avatar
Level 1

Thanks for you help :)

acealphe's avatar

Spend 2 days looking for this. Thank you sutherland

Please or to participate in this conversation.