I have the below factory, and whenever I create the seeder data based on this factory, I get the above-titled error. Please find below the factory code. Mind you; the post_category_id has a type of unsignedBigInteger. I'm surprised it's talking about an array when all I need is a single-digit id referencing the id of the post category table. It's funny that it works when submitting a form.
Error
Illuminate\Database\Grammar::parameterize(): Argument #1 ($values) must be of type array, int given, called in
Factory
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Model>
*/
class PostFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
$tags = ['1', '2', '3', '4', '5'];
return [
'title' => $this->faker->unique()->words(3),
'post_category_id' => $this->faker->numberBetween(1, 50),
'description' => $this->faker->sentences(5),
'tag_id' => json_encode($tags),
'featured' => $this->faker->numberBetween(0, 1),
'status' => 'draft',
'image' => $this->faker->imageUrl()
];
}
}
Migration
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title')->unique()->nullable();
$table->mediumText('description')->nullable();
$table->unsignedBigInteger('post_category_id')->nullable();
$table->text('tag_id')->nullable();
$table->boolean('featured')->default(0);
$table->enum('status', ['draft', 'published'])->nullable();
$table->text('image')->nullable();
$table->timestamps();
});
I've just got to discover that the error message is misleading. I solved the error by simply updating the code as below.