i wanna do php artisan db:seed, then i got this error " ErrorException array_merge(): Expected parameter 2 to be an array, int given"

I wanna make API Authentication Laravel Passport - Forgot and Reset Password with this source video on Youtube : https://www.youtube.com/watch?v=F9Xmc3iHc88&t=6s

My source Youtube use Laravel 6x, and i use Laravel 8x.

When i do step "seeding and factory database" in minute video 8:17 , i got

ErrorException array_merge(): Expected parameter 2 to be an array, int given

This is my error cmd

this is my UserFactory.php :

<?php 
namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\User;

class UserFactory extends Factory
{
 /**
 * The name of the factory's corresponding model.
 *
 * @var string
 */
 protected $model = User::class;

 /**
 * Define the model's default state.
 *
 * @return array
 */
 public function definition()
 {
    return [
        'first_name' => $this->faker->firstName,
        'last_name' => $this->faker->lastName,
        'email' => $this->faker->unique()->safeEmail,
        'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
    ];
}

}

this is my UsersTableSeeder.php :

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\User;

class UsersTableSeeder extends Seeder
{
 /**
 * Run the database seeds.
 *
 * @return void
 */
 public function run()
 {
    User::factory(App\Models\User::class, 10)->create();
 }
}

and my DatabaseSeeder.php :

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder

{
 /**
 * Seed the application's database.
 *
 * @return void
 */
 public function run()
 {
    $this->call(UsersTableSeeder::class);
 }
}

Can someone help me to explain why i got this error merge array?

Upvotes: 1

Views: 1008

Answers (1)

Case Closed guys, in Laravel 8x u dont need type "

User::factory(App\Models\User::class, 10)->create();

just type :

User::factory(10)->create();

because u already call it User at first word..

Upvotes: 2

Related Questions