Level 2
Could be wrong, but have you verified that 'slug' exists in your 'product' migration and has been migrated to your SQL table?
2 likes
My product factory contains a slug:
$factory->define(Product::class, function (Faker $faker) {
return [
'title' => $faker->sentence(4, true),
'slug' => $faker->slug,
'description' => $faker->paragraph,
];
});
My feature test uses the factory to make a new instance:
$product = factory(Product::class)->make();
$response = $this->post('admin/products/store', $product->toArray());
$editPage = $this->get($response->headers->get('Location'));
$editPage->assertSeeText($product->title);
When I run the test I get a SQL error saying the slug is missing:
Error creating product:SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: products.slug (SQL: insert into "products" ("title", "description", "updated_at", "created_at") values (Velit quisquam et accusamus debitis et., Aperiam sint architecto ut sit pariatur aliquid. Et et omnis perspiciatis. Est officiis accusamus enim ut rerum cumque., 2018-02-05 23:58:02, 2018-02-05 23:58:02))
The same approach works in my other feature tests. The test is run as an authenticated admin will all the necessary permissions.
If the slug column is not missing from your migration, check your $fillable or $guarded attribute on your Product model class.
class Product {
// you need this
protected $guarded = [];
// or this
protected $fillable = [
'title',
'slug', // this could be missing if you are using fillable
'description'
];
}
Please or to participate in this conversation.