0

Why it's impossible to create dummy data in unit testing like below?

DB::table('users')->insert([
[
'name' => 'test',
],

I saw that in order to create data you need to create factory, but when I try to insert data like this:

User::factory()->count(1)->create([
'name' => 'test'
]);

It also don't insert new data. What is the easiest way to to that? Thank you

1 Answer 1

2

No need for a factory, and you dont need to use DB if you a User model setup. Laravel is great for these types of things and I recommend reading the docs here

For you problem its as simple as this

User::create(['name' => 'test']);
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, I see my problem was I used RefreshDatabase, so I wasn't able to see data in database..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.