2 years ago

Eloquent doesn't see existing records

Posted 2 years ago by FrenchFryNinja

In PHP artisan tinker I've setup some LabTest objects with a factory method. These are linked with TestCategory in a pivot table. All of these tables are generated via migration.

So this: factory(App\LabTest::class, 75)->create()

creates 75 lab tests like expected.

The TestCategory class has a many-to-many relation with LabTest, but I already have the TestCategory data in a database dump file. So I don't need a factory. What I do need to be able to do is populate the pivot table (lab_test_test_category table), but in order to do that I need to be able to query my existing test categories... and I can't. Why is this happening? If I generate them with a factory, I can see them. Why can't I see the data that's already in the database?

I know I can just build a new factory for the TestCategory rather than try and get this to work, and that's what I'm doing so that I can keep working, but its bugging my why its not working. can anyone help? I'm still pretty new to Laravel.

Please sign in or create an account to participate in this conversation.